CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Help with LCD driver

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
CVD



Joined: 29 Oct 2006
Posts: 3

View user's profile Send private message

Help with LCD driver
PostPosted: Sun Oct 29, 2006 9:27 pm     Reply with quote

Hi all,
I'm playing with the CCS Prototyping Board REv7, with a keypad connected to portD and the LCD is also connected to portD.
I could not see any display on the LCD. The keypad is working O.K. because I could see what I type displayed on the Debug Monitor window (use "#use rs232 (DEBUG))
I don't know how to attach the source code so I'll paste them here. I don't know what I did wrong but nothing can be displayed on the LCD.
Any help will be greatly appreciated.
Thx in advace.
-CD.

[//#use rs232 (DEBUGGER)

#include <EX_lcddriver.c>
#include <EX_kdbdriver.c>

#byte OptionReg = 0x81

void main() {
char k;

lcd_init();
kbd_init();

// OptionReg = 0b10000000;

lcd_putc("\fReady...\n");
//printf("testing....\n");

while (TRUE) {
k=kbd_getc();


#if 0
if(k!=0)
if(k=='*')
lcd_putc('\f');
else
lcd_putc(k);
#else



if(k!=0)
if(k=='*') {
//putc('*');
lcd_putc('\f');
}
else {
//putc(k);
lcd_putc(k);
}
#endif
}
}

---EX_kdbdriver.c
#if defined use_portb_kbd
#byte kbd = 0x06 // on to port B (at address 6)
#else
#byte kbd = 0x08 // on to port D (at address 8)
#endif


#if defined use_portb_kbd
#define set_tris_kbd(x) set_tris_b(x)
#else
#define set_tris_kbd(x) set_tris_d(x)
#endif



//Keypad connection:
// portb/d[0] not used. ROW0-->[1],ROW2-->[2] etc...
#define COL0 (1 << 5)
#define COL1 (1 << 6)
#define COL2 (1 << 7)

#define ROW0 (1 << 1)
#define ROW1 (1 << 2)
#define ROW2 (1 << 3)
#define ROW3 (1 <<4>KBD_DEBOUNCE_FACTOR) {
switch (col) {
case 0 : set_tris_kbd(ALL_PINS&~COL0);
kbd=~COL0&ALL_PINS;
break;
case 1 : set_tris_kbd(ALL_PINS&~COL1);
kbd=~COL1&ALL_PINS;
break;
case 2 : set_tris_kbd(ALL_PINS&~COL2);
kbd=~COL2&ALL_PINS;
break;
}

if(kbd_down) {
if((kbd & (ALL_ROWS))==(ALL_ROWS)) {
kbd_down=FALSE;
kchar=last_key;
last_key='\0';
}
} else {
if((kbd & (ALL_ROWS))!=(ALL_ROWS)) {
if((kbd & ROW0)==0)
row=0;
else if((kbd & ROW1)==0)
row=1;
else if((kbd & ROW2)==0)
row=2;
else if((kbd & ROW3)==0)
row=3;
last_key =KEYS[row][col];
kbd_down = TRUE;
} else {
++col;
if(col==3)
col=0;
}
}
kbd_call_count=0;
}
set_tris_kbd(ALL_PINS);
return(kchar);
}




----#EX_lcddriver.c------------------------------------

struct lcd_pin_map { // This structure is overlayed
BOOLEAN enable; // on to an I/O port to gain
BOOLEAN rs; // access to the LCD pins.
BOOLEAN rw; // The bits are allocated from
BOOLEAN unused; // low order up. ENABLE will
int data : 4; // be pin B0.
} lcd;



#if 0
#byte lcd = 6 // on to port B (at address 6)
#define set_tris_lcd(x) set_tris_b(x)
#endif


#byte lcd = 8 // on to port D (at address 8)
#define set_tris_lcd(x) set_tris_d(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,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>> 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);
}][/code]
CVD



Joined: 29 Oct 2006
Posts: 3

View user's profile Send private message

Found the problem
PostPosted: Sun Oct 29, 2006 10:31 pm     Reply with quote

It was the contrast that needed to be adjusted. Just that.
CVD
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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