Você está na página 1de 8

Programao em Linguagem C Microcontrolador PIC

PIC 18F2550 PIC 18F4550

Prof Paulo Lopes da Silva Jr

Portas I/O Digitais


Registrador TRIS
TRISx = valor valor = TRISx TRISxbitsxy = valor_bit valor_bit = TRISxbitsxy

Registrador PORT
PORTx = valor valor = PORTx PORTxbits.PORTxy = valor_bit valor_bit = PORTxbits.PORTxy

Registrador LAT
LATx = valor valor = LATx LATxbits.LATxy = valor_bit valor_bit = LATxbits.LATxy

Obs: x: nome da porta (letra maiscula) y: nnero do pino valor_bit: valor 0 (sada) valor 1 (entrada)

Portas I/O Digitais

Portas I/O Digitais


#include <p18f4550.h> #include <adc .h> <adc.h> // Fosc = 20MHz // Tciclo = 4 /Fosc /Fosc = 0,2us #pragma config FOSC = HS #pragma config CPUDIV = OSC1_PLL2 #pragma config WDT = OFF //Desabilita o Watchdog Timer (WDT). #pragma config PWRT = ON //Habilita o PowerPower-up Timer (PWRT). #pragma config BOR = ON //Brown -out Reset (BOR) habilitado //Brownsomente no hardware. #pragma config BORV = 1 //Voltagem do BOR 4,33V. #pragma config PBADEN = OFF //RB0,1,2,3 e 4 configurado como I/O digital. #pragma config LVP = OFF //Desabilita o Low Voltage Program. Program. #define B_LED_1 PORTBbits.RB5 PORTBbits.RB5 #define B_LED_2 PORTBbits.RB6 PORTBbits.RB6 #define B_RELE PORTBbits.RB7 PORTBbits.RB7 #define LED_1 PORTEbits.RE0 PORTEbits.RE0 #define LED_2 PORTEbits.RE1 PORTEbits.RE1 #define RELE PORTEbits.RE2 PORTEbits.RE2 } } void main( main(void) void) { TRISA = 0b00011111; TRISB = 0b11100111; TRISC = 0b10111111; TRISD = 0b00000000; TRISE = 0b00000000; openADC(0x00,0x00,ADC_0ANA); openADC(0x00,0x00,ADC_0ANA); closeADC( closeADC( ); while(1) while(1) { if(B_LED_1 if(B_LED_1 == 0) { LED_1 = 1;} else { LED_1 = 0;} if(B_LED_2 if(B_LED_2 == 0) { LED_2 = 1;} else { LED_2 = 0;} if(B_RELE if(B_RELE == 0) { RELE = 1;} else { RELE = 0;}

Display LCD 2x16


Pinagem LCD 2x16

Display LCD 2x16

Display LCD 2x16


Defini Definies dos Pinos
#ifndef Fosc #define Fosc 20 //Define a freq freqncia do oscilador. Este valor deve corresponder a freq freqncia do oscilador utilizado pelo PIC18. #endif // Os nome definidos so os pr prprios nomes dos pinos do display LCD. #define B7 PORTBbits.RB2 PORTBbits.RB2 //Define o nome B7 para a estrutra. estrutra. #define E_B7 TRISBbits.TRISB2=1; TRISBbits.TRISB2=1; #define S_B7 TRISBbits.TRISB2=0; TRISBbits.TRISB2=0; #define B6 PORTBbits.RB4 PORTBbits.RB4 //Define o nome B6 para a estrutra. estrutra. #define E_B6 TRISBbits.TRISB4=1; .TRISB4=1; TRISBbits #define S_B6 TRISBbits.TRISB4=0; TRISBbits.TRISB4=0; #define B5 PORTBbits.RB5 PORTBbits.RB5 //Define o nome B5 para a estrutra. estrutra. #define E_B5 TRISBbits.TRISB5=1; TRISBbits.TRISB5=1; #define S_B5 TRISBbits.TRISB5=0; TRISBbits.TRISB5=0; #define B4 PORTBbits.RB6 PORTBbits.RB6 //Define o nome B4 para a estrutra. estrutra. #define E_B4 TRISBbits.TRISB6=1; TRISBbits.TRISB6=1; #define S_B4 TRISBbits.TRISB6=0; TRISBbits.TRISB6=0; #define E PORTBbits.RB7 PORTBbits.RB7 //Define o nome E para a estrutra. estrutra. #define E_E TRISBbits.TRISB7=1; TRISBbits.TRISB7=1; #define S_E TRISBbits.TRISB7=0; TRISBbits.TRISB7=0; #define RW PORTBbits.RB1//Define PORTBbits.RB1//Define o nome RW para a estrutra. estrutra. #define E_RW TRISBbits.TRISB1=1; TRISBbits.TRISB1=1; #define S_RW TRISBbits.TRISB1=0; TRISBbits.TRISB1=0; #define RS PORTBbits.RB0 PORTBbits.RB0 //Define o nome RS para a estrutra. estrutra. #define E_RS TRISBbits.TRISB0=1; TRISBbits.TRISB0=1; #define S_RS TRISBbits.TRISB0=0; TRISBbits.TRISB0=0;

Display LCD 2x16


Carter Especial lcd_envia_controle(0,0,0x40,2); lcd_escreve_dado(0x01); lcd_escreve_dado(0x04); lcd_escreve_dado(0x1C); lcd_escreve_dado(0x1D); lcd_escreve_dado(0x1C); lcd_escreve_dado(0x04); lcd_escreve_dado(0x01); lcd_escreve_dado(0x00);

Você também pode gostar