Amigos del foro:
Ultimamente me quiero romper la cabeza contra la pared por problemas causados por ciertos bugs (creo yo) de nuestro querido compilador CCS.
Resulta que por conveniencia decide reacomodar los pines de la libreria LCD.C ademas lo traslade al puerto D, (pongo libreria y codigo a continuacion), resulta que cuando inicializo esta libreria con lcd_init(), automaticamente pierdo la facultad de poder transmitir a traves del USART, aun asi puedo seguir recibiendo.
Como me di cuenta de esto? Facil, hice un codigo donde primero, transmito (y funciona), luego digo "hola mundo", vuelvo a transmitir, y nada... despues activo la interrupcion RDA y pues veo en pantalla que si recibo, puse un echo para ver retransmitir lo recibido, y tampoco logro recibir nada. Cuando recompilo y comento las lineas que tengan que ver con LCD pues voila! todo normal, transmision y recepcion de vuelta a la normalidad.
Les comento que ya tengo la placa construida, asi que volver el LCD donde deberia estar no es una opcion. Ademas, esto es muy raro, pues antes el programa funcionaba sin ningun problema.
Tampoco es el PIC, ya que probe con 3 diferentes, y por si acaso reinstale el compilador.
Espero puedan ayudarme, aca va el programa.... Saludos!
// Un-comment the following define to use port B
//#define use_portb_lcd TRUE
struct lcd_pin_map { // This structure is overlayed
BOOLEAN unused/*enable*/; // on to an I/O port to gain
BOOLEAN rw/*rs*/; // access to the LCD pins.
BOOLEAN rs/*enablerw*/; // The bits are allocated from
BOOLEAN enable/*rsunused*/; // low order up. ENABLE will
int data : 4; // be pin B0.
} lcd;
#if defined use_portb_lcd
#locate lcd = getenv("sfr:PORTB") // This puts the entire structure over the port
#define set_tris_lcd(x) set_tris_b(x)
#else
#locate lcd = getenv("sfr:PORTD") // This puts the entire structure over the port
#define set_tris_lcd(x) set_tris_d(x)
#endif
#define lcd_type 2 // 0=5x7, 1=5x10, 2=2 lines
#define lcd_line_two 0x40 // LCD RAM address for the second line
BYTE const LCD_INIT_STRING[4] = {0x20 | (lcd_type << 2), 0xc, 1, 6};
// These bytes need to be sent to the LCD
// to start it up.
//AGREGADO - ASC
#define LCD_BLINK 0
#define LCD_CURSOR 1
#define LCD_ONOFF 2
int LCD_FUNCTION = LCD_INIT_STRING[1];
//FIN AGREGADO - ASC
// The following are used for setting
// the I/O port direction register.
struct lcd_pin_map const LCD_WRITE = {0,0,0,0,0}; // For write mode all pins are out
struct lcd_pin_map const LCD_READ = {0,0,0,0,15}; // For read mode data pins are in
BYTE lcd_read_byte() {
BYTE low,high;
set_tris_lcd(LCD_READ);
lcd.rw = 1;
delay_cycles(1);
lcd.enable = 1;
delay_cycles(1);
high = lcd.data;
lcd.enable = 0;
delay_cycles(1);
lcd.enable = 1;
delay_us(1);
low = lcd.data;
lcd.enable = 0;
set_tris_lcd(LCD_WRITE);
return( (high<<4) | low);
}
void lcd_send_nibble( BYTE n ) {
lcd.data = n;
delay_cycles(1);
lcd.enable = 1;
delay_us(2);
lcd.enable = 0;
}
void lcd_send_byte( BYTE address, BYTE n ) {
lcd.rs = 0;
while ( bit_test(lcd_read_byte(),7) ) ;
lcd.rs = address;
delay_cycles(1);
lcd.rw = 0;
delay_cycles(1);
lcd.enable = 0;
lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}
void lcd_init() {
BYTE i;
set_tris_lcd(LCD_WRITE);
lcd.rs = 0;
lcd.rw = 0;
lcd.enable = 0;
delay_ms(15);
for(i=1;i<=3;++i) {
lcd_send_nibble(3);
delay_ms(5);
}
lcd_send_nibble(2);
for(i=0;i<=3;++i)
lcd_send_byte(0,LCD_INIT_STRING[i]);
}
void lcd_gotoxy( BYTE x, BYTE y) {
BYTE address;
if(y!=1)
address=lcd_line_two;
else
address=0;
address+=x-1;
lcd_send_byte(0,0x80|address);
}
void lcd_putc( char c) {
switch (c) {
case '\f' : lcd_send_byte(0,1);
delay_ms(2);
break;
case '\n' : lcd_gotoxy(1,2); break;
case '\b' : lcd_send_byte(0,0x10); break;
default : lcd_send_byte(1,c); break;
}
}
char lcd_getc( BYTE x, BYTE y) {
char value;
lcd_gotoxy(x,y);
while ( bit_test(lcd_read_byte(),7) ); // wait until busy flag is low
lcd.rs=1;
value = lcd_read_byte();
lcd.rs=0;
return(value);
}
//AGREGADO ASC
void lcd_cursorOnOff(int OnOff) {
// #bit LCD_CURSOR_BIT = LCD_FUNCTION.LCD_CURSOR // 1
#bit LCD_CURSOR_BIT = LCD_FUNCTION.LCD_CURSOR
LCD_CURSOR_BIT = OnOff ;
//lcd_send_byte(0,LCD_FUNCTION);
lcd_send_byte(0,LCD_FUNCTION);
delay_us (50);
}
void lcd_BlinkOnOff(int OnOff)
{
// #bit LCD_CURSOR_BIT = LCD_FUNCTION.LCD_CURSOR // 1
#bit LCD_BLINK_BIT = LCD_FUNCTION.LCD_BLINK
LCD_BLINK_BIT = OnOff ;
//lcd_send_byte(0,LCD_FUNCTION);
lcd_send_byte(0,LCD_FUNCTION);
delay_us (50);
}
//FIN AGREGADO - ASC
#include "C:\Program Files\PICC\Devices\16F877A.h"
#use delay(clock=4000000)
#include "LCD_3.c"
#FUSES NOWDT //No Watch Dog Timer
#FUSES XT //Crystal osc <= 4mhz for PCM/PCH , 3mhz to 10 mhz for PCD
#FUSES PUT //Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#FUSES BROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD //No EE protection
#FUSES NOWRT //Program memory not write protected
#define SelA PIN_A1
#define SelB PIN_A2
#define INH PIN_A5
#define BUZZ PIN_C5
#use rs232(baud=9600, parity=N, xmit=PIN_C6, rcv=PIN_C7, bits=8, STREAM = COM)
#use fast_io(c)
#use fast_io(d)
#INT_RDA
void rda_isr()
{
char c;
if(kbhit())
{
c = getc();
lcd_putc("\f REC = ");
lcd_putc(c);
putc(c,COM);
}
}
void main()
{
char c;
int i=0;
set_tris_c(0b10001000);
set_tris_d(0x00);
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
port_b_pullups(false);
ext_int_edge(0,H_TO_L);
enable_interrupts(GLOBAL);
enable_interrupts(INT_RDA);
clear_interrupt(INT_RDA);
while(i<10)
{
puts("PC");
delay_ms(100);
puts("RFID");
delay_ms(100);
puts("Net");
delay_ms(100);
i++;
}
lcd_init();
delay_ms(100);
lcd_putc("\f HOLA MUNDO\n");
lcd_putc("HOLA");
delay_ms(500);
do
{
fprintf(COM,"PC");
delay_ms(100);
fprintf(COM,"RFID");
delay_ms(100);
fprintf(COM,"Net");
delay_ms(100);
}
while(1);
}