Baixe o app para aproveitar ainda mais
Prévia do material em texto
MICROCONTROLADORES Prof. Ghunter Paulo ENGENHARIA ELÉTRICA MICROCONTROLADORES ALUNO (a):______________________________________________ Entrega: 13/05/2022 até 18:00h Valor: 10 NOTA Exercício Faça um programa em Linguagem C que acione o Motor CC usando microcontrolador PIC18F4550 de acordo com o hardware apresentado na figura abaixo. O Motor deve ser ligado e permanecer ligado durante um período de tempo configurado via teclado (Máx: 999s) O motor só deverá ser desligado depois que o temporizador for zerado O temporizador deve ser ajustado pelo usuário através do teclado matricial Utilize a tecla # para iniciar a contagem e * para limpar o temporizador Após fazer o código no MikroC copie e cole logo abaixo do enunciado da questão, no local indicado. O Hardware do Proteus está disponível no Moodle. Gere um arquivo PDF e anexe no moodle até a data de entrega MICROCONTROLADORES Prof. Ghunter Paulo Enquanto o motor estiver ligado, o led L1 deverá estar acesso e a uma mensagem “M1 LIG” deve aparecer no LCD. Enquanto o motor estiver desligado o led L2 deverá estar acesso e a mensagem “M1 DES” deve aparecer no LCD. A contagem do temporizador deve aparecer no LCD Todo o sistema só deverá funcionar se a chave 1 estiver fechada. COLE O CÓDIGO AQUI sbit LCD_RS at RB2_bit; sbit LCD_EN at RB3_bit; sbit LCD_D4 at RB4_bit; sbit LCD_D5 at RB5_bit; sbit LCD_D6 at RB6_bit; sbit LCD_D7 at RB7_bit; sbit LCD_RS_Direction at TRISB2_bit; sbit LCD_EN_Direction at TRISB3_bit; sbit LCD_D4_Direction at TRISB4_bit; sbit LCD_D5_Direction at TRISB5_bit; sbit LCD_D6_Direction at TRISB6_bit; sbit LCD_D7_Direction at TRISB7_bit; int teclado(); void main(){ int aux, C, D, U, cont, ent, a, XU, XD, XC; ADCON1 = 15; trisb = 0; Lcd_Init(); Lcd_Cmd(_LCD_CLEAR); Lcd_Cmd(_LCD_CURSOR_OFF); trisd=0b00011111; trisa=0; porta=0; portb=0; trisc=0; portc=0; LCD_OUT(1,1," TEMPO: "); while(1) { MICROCONTROLADORES Prof. Ghunter Paulo aux=teclado(); if(aux!=13 && aux!=10) { cont++; if(cont==1) { C=aux; LCD_CHR(1,10, C+48); ent=C; } if(cont==2) { D=aux; LCD_CHR(1,11, D+48); ent=(C*10)+D; } if(cont==3) { U=aux; LCD_CHR(1,12, U+48); } if(cont==2 && aux==11) { PORTC.F7=1; PORTC.F4=1; LCD_OUT(2,1, " M1 LIGADO "); LCD_OUT(1,10," "); ent=C; for(a=ent;a>=0;a=a-1) { delay_ms(100); LCD_CHR(1,12, a+48); if(a==0) { PORTC.F4=0; PORTC.F7=0; PORTC.F5=1; LCD_OUT(2,1, "M1 DESLIGADO "); LCD_OUT(1,10," "); } } } else if (cont==3 && aux==11) { PORTC.F7=1; PORTC.F4=1; LCD_OUT(2,1, " M1 LIGADO "); LCD_OUT(1,10," "); MICROCONTROLADORES Prof. Ghunter Paulo ent=(C*10)+D; for(a=ent;a>=0;a=a-1) { delay_ms(100); XD=a/10; XU=a%10; LCD_CHR(1,11, XD+48); LCD_CHR(1,12, XU+48); if(a==0) { PORTC.F4=0; PORTC.F7=0; PORTC.F5=1; LCD_OUT(2,1, "M1 DESLIGADO "); } } } else if (cont==4 && aux==11) { PORTC.F7=1; PORTC.F4=1; LCD_OUT(2,1, " M1 LIGADO "); ent=(C*100)+(D*10)+U; for(a=ent;a>=0;a=a-1) { delay_ms(100); XC=a/100; XD=(a%100)/10; XU=(a%100)%10; LCD_CHR(1,10, XC+48); LCD_CHR(1,11, XD+48); LCD_CHR(1,12, XU+48); if(a==0) { PORTC.F4=0; PORTC.F7=0; PORTC.F5=1; LCD_OUT(2,1, "M1 DESLIGADO "); } } } } else if(aux==10) { PORTC.F7=0; cont=0; LCD_OUT(1,10, " "); } MICROCONTROLADORES Prof. Ghunter Paulo } } int teclado() { int tecla=13; delay_ms(20); portd.f5=0; portd.f6=1; portd.f7=1; while(portd.f1==0)tecla=1; while(portd.f2==0)tecla=4; while(portd.f3==0)tecla=7; while(portd.f4==0)tecla=10; portd.f5=1; portd.f6=0; portd.f7=1; while(portd.f1==0)tecla=2; while(portd.f2==0)tecla=5; while(portd.f3==0)tecla=8; while(portd.f4==0)tecla=0; portd.f5=1; portd.f6=1; portd.f7=0; while(portd.f1==0)tecla=3; while(portd.f2==0)tecla=6; while(portd.f3==0)tecla=9; while(portd.f4==0)tecla=11; return(tecla); }
Compartilhar