Guard
Joined: 20 Jan 2005 Posts: 43
|
18F442 and LCD.C not works |
Posted: Fri Mar 18, 2005 8:38 am |
|
|
PCWH 3.221
My lcd don't work !,
The hardware is ok, I tested it by asm routine
Where is the error in my code?
Thanks!
Code: |
struct lcd_map { // This structure is overlayed
int data : 4;
boolean D4; // non usato per lcd
boolean D5; // non usato per lcd
boolean D6; // non usato per lcd
boolean D7;
} lcd;
#byte lcd=0xf83
#byte PORTC=0xf82
#BIT RS= PORTC.5
#BIT E= PORTC.6
restart_wdt();
#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};
// The following are used for setting
// the I/O port direction register.
STRUCT lcd_map const LCD_WRITE = {0,0,0,0,0}; // For write mode all pins are out
void lcd_send_nibble( byte n ) {
lcd.data = n;
delay_us(10) ; //2
RESTART_WDT();
output_high(PIN_C6);
delay_us(10); //2
output_low(PIN_C6);
}
void lcd_send_byte( byte address, byte n ) {
RESTART_WDT();
rs = 0;
delay_us(50);
rs = address;
delay_us(25);//2
delay_us(15); //2
output_low(PIN_C6);
lcd_send_nibble(n >> 4);
lcd_send_nibble(n & 0xf);
}
void lcd_init() {
byte i;
set_tris_C(LCD_WRITE);
set_tris_D(LCD_WRITE);
rs = 0;
output_low(PIN_C6);
delay_ms(50);
RESTART_WDT();
for(i=1;i<=3;++i) {
lcd_send_nibble(3);
delay_ms(5); //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);
RESTART_WDT();
}
void lcd_putc( char c) {
switch (c) {
case '\f' : lcd_send_byte(0,1);
delay_ms(2);
break;
default : lcd_send_byte(1,c); break;
}
}
|
|
|