![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Gabriel Caffese
Joined: 09 Oct 2003 Posts: 39 Location: LA PLATA, ARGENTINA
|
Enabling LCD disables #INT_RDA !!! |
Posted: Sat Jan 22, 2005 3:36 pm |
|
|
Hello everyone,
The program shows characters ok, but enabling the RDA_ISR does not allow me to receive any data.
If I don´t use the LCD initialization, the RDA_ISR allows me to receive data, so, the problem is due to
the LCD_16F routine (wich is the CCS´s LCD library, but with pinouts modified).
I´ve tested 1000 times. Is it wrong, and I can not see where ???
I will appreciate any help.
Here is the code:
Code: |
#include <16F88.H>
#fuses INTRC_IO,NOWDT,NOBROWNOUT,NOPROTECT,PUT,NOLVP,NOMCLR
#use delay(clock=8000000)
#use rs232(baud=38400, bits=8, xmit=PIN_B5, rcv=PIN_B2, ERRORS)
#include <LCD_16F.C>
static char Rx[16];
static int1 INTERRUPCION;
static int8 i;
#int_rda
void serial_isr()
{
Rx[i++]=getc();
INTERRUPCION=TRUE;
}
void main()
{
#ZERO_RAM
// Seteo oscilador a 8Mhz //
#use delay(clock=8000000)
setup_oscillator(OSC_8MHZ);
// Configuro periféricos para bajo consumo //
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,2);
setup_ccp1(CCP_OFF);
setup_adc(ADC_OFF);
setup_vref(FALSE);
// Configuro puertos para bajo consumo //
port_b_pullups(TRUE);
// Configuro interrupciones //
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
// Inicializo display 16*2 //
lcd_init();
// Inicializo variables //
INTERRUPCION=FALSE;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
printf(lcd_putc,"\fABCDEFGHIJKLMNOP");
printf(lcd_putc,"\n1234567890123456");
delay_ms(1000);
printf(lcd_putc,"\f1234567890123456");
printf(lcd_putc,"\nABCDEFGHIJKLMNOP");
delay_ms(1000);
printf(lcd_putc,"\f");
Loop:
if ( (INTERRUPCION==TRUE) && (i==15) )
{
printf(lcd_putc,"\f%s",Rx);
INTERRUPCION=FALSE;
i=0;
}
goto Loop;
}
|
And the LCD routine:
Code: |
///////////////////////////////////////////////////////////////////////////
//// LCDD.C ////
//// Driver for common LCD modules ////
//// ////
//// lcd_init() Must be called before any other function. ////
//// ////
//// lcd_putc(c) Will display c on the next position of the LCD. ////
//// The following have special meaning: ////
//// \f Clear display ////
//// \n Go to start of second line ////
//// \b Move back one position ////
//// ////
//// lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1) ////
//// ////
//// lcd_getc(x,y) Returns character at position x,y on LCD ////
//// ////
///////////////////////////////////////////////////////////////////////////
struct lcd_pin_map
{ // This structure is overlayed
BOOLEAN enable; // on to an I/O port to gain
BOOLEAN rw; // access to the LCD pins.
BOOLEAN unused; // The bits are allocated from
BOOLEAN rs; // low order up. ENABLE will
int data : 4; // be pin B0.
} lcd;
#byte lcd = 6 // on to port B (at address 6)
#define set_tris_lcd(x) set_tris_b(x)
#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.
// The following are used for setting
// the I/O port direction register.
struct lcd_pin_map const LCD_WRITE = {0,0,1,0,0}; // For write mode all pins are out
struct lcd_pin_map const LCD_READ = {0,0,1,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) );
lcd.rs=1;
value = lcd_read_byte();
lcd.rs=0;
return(value);
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sat Jan 22, 2005 5:53 pm |
|
|
try this for your LCD.C
Code: |
struct lcd_pin_map
{
BOOLEAN enable;
BOOLEAN rw;
BOOLEAN dummy;
BOOLEAN rs;
int data : 4;
} lcd;
#locate lcd = 6
struct lcd_tris_map
{
BOOLEAN enable;
BOOLEAN rw;
BOOLEAN dummy;
BOOLEAN rs;
int data : 4;
} lcdtris;
#locate lcdtris = 0x86
#define set_tris_lcd(x) lcdtris.data = (x); lcdtris.enable = 0; lcdtris.rw = 0; lcdtris.rs = 0;
#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.
// The following are used for setting
// the I/O port direction register.
#define LCD_WRITE 0 // For write mode all pins are out
#define LCD_READ 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);
lcd.rs=1;
value = lcd_read_byte();
lcd.rs=0;
return(value);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Guest
|
|
Posted: Sun Jan 23, 2005 8:54 am |
|
|
Mark.
Thanks for your code, but the problem was still the same. I´ve solved it, migrating LCD pins to port A. This way, interrupts work as should.
If anyone needs to control and LCD with port A, just ask me for the code.
Gabriel.- |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|