O Programa foi feito no CCS, e estou simulando no Proteus e testando no circuito os dois fazem a mesma coisa, não recebem.
Se alguem já tiver tido este mesmo problema e puder me ajudar.
Segue o Programa da central:
- Código: Selecionar todos
#include <18F452.h>
#device adc=8
#FUSES NOWDT //No Watch Dog Timer
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale
#FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES NOPROTECT //Code not protected from reading
#FUSES NOOSCSEN //Oscillator switching is disabled, main oscillator is source
#FUSES BROWNOUT //Reset when brownout detected
#FUSES BORV27 //Brownout reset at 2.7V
#FUSES NOPUT //No Power Up Timer
#FUSES STVREN //Stack full/underflow will cause reset
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT //Program memory not write protected
#FUSES NOWRTD //Data EEPROM not write protected
#FUSES NOWRTB //Boot block not write protected
#FUSES NOWRTC //configuration not registers write protected
#FUSES NOCPD //No EE protection
#FUSES NOCPB //No Boot Block code protection
#FUSES NOEBTR //Memory not protected from table reads
#FUSES NOEBTRB //Boot block not protected from table reads
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=RS232)
#use rs232(baud=9600,parity=N,xmit=PIN_D7,rcv=PIN_D5,bits=8,stream=RS485,enable=PIN_D6)
////////////////////////////////////////////////////////////////////////////////
// //
// Definição de palavras //
// //
////////////////////////////////////////////////////////////////////////////////
#define en_chip_1 pin_c1
#define en_chip_2 pin_c2
#define rs pin_c0
#define barramento output_b
////////////////////////////////////////////////////////////////////////////////
// //
// Rotina de envio de comando para o chip 1 do lcd //
// //
////////////////////////////////////////////////////////////////////////////////
void comando_lcd_chip_1(unsigned int8 comando_chip_1)
{
barramento(comando_chip_1);
output_low(rs);
output_high(en_chip_1);
delay_ms(1);
output_low(en_chip_1);
}
////////////////////////////////////////////////////////////////////////////////
// //
// Rotina de envio de comando para o chip 2 do lcd //
// //
////////////////////////////////////////////////////////////////////////////////
void comando_lcd_chip_2(unsigned int8 comando_chip_2)
{
barramento(comando_chip_2);
output_low(rs);
output_high(en_chip_2);
delay_ms(1);
output_low(en_chip_2);
}
////////////////////////////////////////////////////////////////////////////////
// //
// Rotina de inicialização do lcd //
// //
////////////////////////////////////////////////////////////////////////////////
void inicia_lcd(void)
{
comando_lcd_chip_1(0x38);
comando_lcd_chip_2(0x38);
comando_lcd_chip_1(0x38);
comando_lcd_chip_2(0x38);
comando_lcd_chip_1(0x06);
comando_lcd_chip_2(0x06);
comando_lcd_chip_1(0x0c);
comando_lcd_chip_2(0x0c);
comando_lcd_chip_1(0x01);
comando_lcd_chip_2(0x01);
}
////////////////////////////////////////////////////////////////////////////////
// //
// Rotina de envio de dados para o chip 1 do lcd //
// //
////////////////////////////////////////////////////////////////////////////////
void dado_lcd_chip_1(unsigned int8 dado_chip_1)
{
barramento(dado_chip_1);
output_high(rs);
output_high(en_chip_1);
delay_us(40);
output_low(en_chip_1);
}
////////////////////////////////////////////////////////////////////////////////
// //
// Rotina de envio de dados para o chip 2 do lcd //
// //
////////////////////////////////////////////////////////////////////////////////
void dado_lcd_chip_2(unsigned int8 dado_chip_2)
{
barramento(dado_chip_2);
output_high(rs);
output_high(en_chip_2);
delay_us(40);
output_low(en_chip_2);
}
void main()
{
int8 x;
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
inicia_lcd();
x=0;
while(1)
{
fputc(155,RS485);
x=fgetc(RS485);
comando_lcd_chip_1(0x80);
printf(dado_lcd_chip_1,"VALOR: %u ",x);
}
}