Pesquisar neste blog

12/03/2023

Prova 1 #2022/1

1.1. Crie um programa e faça as ligações necessárias para que os LED liguem e desliguem com frequências iguais as indicadas a seguir:

LED1 = 5Hz         Vi >= 0 e Vi  < 0,8v
LED2 = 10Hz         Vi >= 0,8 e Vi < 1,6v
LED3 = 20Hz         Vi >= 1,6 e Vi < 2,4v
LED4 = 50Hz         Vi >= 2,4 e Vi < 3,2v
LED5 = 100Hz Vi >= 3,2 e Vi < 4v
LED6 =                    Liga quando Vi >= 4v














Resolução feita no CCS C Compiler

#include <16F877A.h>
#device adc = 8
#FUSES NOWDT, HS, NOPUT, NOPROTECT, NODEBUG, BROWNOUT, NOLVP, NOCPD, NOWRT, NOWRT
#use delay(clock = 20MHz)
#include <lcd.c>
#use standard_io (b)
/*Crie um programa e faça as ligações para que os LED liguem e desliguem com 
frequências iguais as indicadas a seguir:
LED1 = 5HZz Vi >= 0V e Vi < 0,8V
LED2 = 10Hz Vi >= 0,8V e Vi < 1,6V
LED3 = 20HZ Vi >= 1,6 e Vi < 2,4V
LED4 = 50HZ Vi >= 2,4 e Vi < 3,2V
LED5 = 100HZ Vi >= 3,2 e Vi < 4V
LED6 = Liga quando Vi >= 4V
*/
unsigned int8 analog, frequencia, tempo;
float tensao;
unsigned int16 cont0 = 0, cont1 = 0, cont2 = 0, cont3 = 0, cont4 = 0, cont5 = 0;

#int_TIMER0
void TIMER0_isr(float tensao){
         
   if(tensao >= 0.01 && tensao < 0.8){
      printf(lcd_putc,"\fTENSAO = %1.2f V\nFREQ= 5 Hz", tensao);      
      if(++cont1 >= 1970) {cont1 = 0; output_toggle(PIN_B0);}   // 5HZ   ok
      
   }else if(tensao >= 0.80 && tensao < 1.60){
      printf(lcd_putc,"\fTENSAO = %1.2f V\nFREQ= 10 Hz", tensao); 
      if(++cont2 >= 750) {cont2 = 0; output_toggle(pin_B1);}   //10 HZ  ok
      
   }else if(tensao >= 1.60 && tensao < 2.40){
      printf(lcd_putc,"\fTENSAO = %1.2f V\nFREQ= 20 Hz", tensao); 
      if(++cont3 >= 240) {cont3 = 0; output_toggle(pin_B2);}   // 20 Hz  
      
   }else if(tensao >= 2.40 && tensao < 3.20){
      printf(lcd_putc,"\fTENSAO = %1.2f V\nFREQ= 50 Hz", tensao); 
      if(++cont4 >= 98) {cont4 = 0; output_toggle(pin_B3);}   // 50 Hz
      
   }else if(tensao >= 3.20 && tensao < 4.0){
      printf(lcd_putc,"\fTENSAO = %1.2f V\nFREQ= 100 Hz", tensao); 
      if(++cont5 >= 39) {cont5 = 0; output_toggle(pin_B4);}    // 100 Hz
   }else if(tensao >= 4.0){
      output_high(PIN_B5);
   }
   
}

void main(){
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_psp(PSP_DISABLED);
   setup_spi(SPI_SS_DISABLED);   
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED, 0, 1);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   setup_adc(ADC_CLOCK_DIV_32);           // Set ADC conversion time to 32Tosc
   setup_adc_ports(AN0);          // Configure AN0,AN1 and AN3 as analog   
   set_adc_channel(0);                    // Select channel AN1     
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);
   lcd_init();
   
   while(true) {
      analog = read_adc();
      tensao = (5.0 / 255.0) * analog;
      printf(lcd_putc,"\fTENSAO = %1.2f V\nT= %ums \tFREQ= %uHz",tensao, tempo, frequencia);
            
      TIMER0_isr(tensao);
            
   }
}


















































2. 2. Crie um programa e faça as ligações (cristal, resistor, alimentação, ...) necessárias para que os displays apresentem uma luz circulante no sentido horário (a, b, c, d, d', e', f', a', a, b,...). Onde d', e', f' e a', são segmento do display  catodo comum. A velocidade dependerá da posição do potenciômetro.















Resolução em código feito no CCS C Compiler

#include <16F877A.h>
#device adc = 8
#use delay(clock = 20MHz)
#FUSES HS,NOWDT,NOPROTECT,NOLVP

unsigned int8 vet1[] = {0b00001000, 0b00010000, 0b00100000, 0b00000001};
unsigned int8 vet2[] = {0b11111110, 0b11111101, 0b11111011, 0b11110111};

int size = sizeof(vet1)/sizeof(int); // tamanho do vetor vet1
unsigned int16 leia;

void main(void){
  setup_adc(ADC_CLOCK_DIV_32);           // Set ADC conversion time to 32Tosc
  setup_adc_ports(AN0_AN1_AN3);          // Configure AN0,AN1 and AN3 as analog
  setup_ccp2(CCP_PWM);                   // Configure CCP2 as a PWM
  setup_timer_2(T2_DIV_BY_16, 255, 1);   // Set PWM frequency to 488Hz
  set_adc_channel(0);                    // Select channel AN1
  
  while(true){
                        
      leia = read_adc();                 // Read from AN1 and store in j
      
      for(int i = 0; i < size; i++){
         output_d(vet1[i]);
         delay_ms(leia);
      }      
      
      for(int j = 0; j < size; j++){
         output_d(vet2[j]);
         delay_ms(leia);
      }
   }
}




3. Desenvolva um programa para acionar o motor de passo a seguir. Para girar no sentido 1 (b1, b2, b3, b4, b1, b2,...) e no sentido contrário devem ser acionadas as bobinas (b4, b3, b2, b1, b4, b3,...) Utilize um botão para inverter o sentido. O motor deve girar com velocidade de 100 rpm (rpm = rotações por minuto) no sentido horário e 75 rpm no sentido anti-horário.













Resolução feita no CCS C Compiler

#include <16F877A.h>
#fuses XT, HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock = 20MHz)
#include <lcd.c>

#define t1 150
#define t2 200

#use fast_io(B)

unsigned int horario[9] = {0b00010000, 0b00110000, 0b01110000, 0b01100000, 0b11100000, 0b11000000, 0b10000000, 0b10010000};
unsigned int antiHorario[9] = {0b10000000, 0b11000000, 0b01000000, 0b01100000, 0b00100000, 0b00110000, 0b00010000, 0b10010000};
int i = 0, cont = 0;

#INT_EXT
ext_isr(){
   cont++;
   if(cont >= 4) {cont = 0;}
}

void main(){
   set_tris_b(0x01);
   output_low(PIN_B7);
   port_b_pullups(TRUE);
   enable_interrupts(int_ext);
   ext_int_edge(L_TO_H);
   enable_interrupts(GLOBAL);
   
   lcd_init();
   
   while(true){
      printf(lcd_putc, "\fMOTOR OFF !");
      delay_ms(500);
   
      while(cont == 1){
         output_b(horario[i]);
         lcd_gotoxy(1, 1);
         delay_ms(t1);
         i++;
         if(++i >= 8) {i = 0;}
         
         lcd_gotoxy(1, 1);
         printf(lcd_putc, "\fMOTOR ON");
         lcd_gotoxy(1,2);
         printf(lcd_putc, "SENTIDO HORARIO");
         lcd_gotoxy(21,1);
         printf(lcd_putc, "Freq = 100 RPM");
         lcd_gotoxy(21,2);
         printf(lcd_putc, "Freq = 10.47 rad/s");
      }
   
      while(cont == 3){
         output_b(antiHorario[i]);
         delay_ms(t2);
         i++;
         if(++i >= 8) {i = 0;}
         
         lcd_gotoxy(1, 1);
         printf(lcd_putc, "\fMOTOR ON");
         lcd_gotoxy(1,2);
         printf(lcd_putc, "SENTIDO ANTI-HORARIO");
         lcd_gotoxy(21,1);
         printf(lcd_putc, "Freq = 75 RPM");
         lcd_gotoxy(21,2);
         printf(lcd_putc, "Freq = 7.85 rad/s");
      }
   }
}

Software Proteus versão 7.9
























Nenhum comentário: