With a 595 shift register shifting one wire lcd.
Revision 0:9245c05647c9, committed 2011-02-22
- Comitter:
- ahmetunal
- Date:
- Tue Feb 22 10:41:38 2011 +0000
- Commit message:
Changed in this revision
1wire_lcd.cpp | Show annotated file Show diff for this revision Revisions of this file |
1wire_lcd.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 9245c05647c9 1wire_lcd.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/1wire_lcd.cpp Tue Feb 22 10:41:38 2011 +0000 @@ -0,0 +1,116 @@ +#include "1wire_lcd.h" +#include "mbed.h" + +DigitalOut wire(p21); + + +void one_wire(unsigned char data) +{ + char i; + wire=1; + for(i=0;i < 8;i++) + { + if((data<<(i))&0x80) + { + wire=0; + wire=1; + } + else + { + wire=0; + wait_us(15); + wire=1; + wait_us(30); + } + } + wire=0; + wait_us(210); + wire=1; + wait_us(300); +} + + +void lcd_putc(unsigned char c) +{ + unsigned char data; + data = 0x00; + data |=0x50; + one_wire(data); + data |= ((c & 0xF0)>>4); + one_wire(data); + data &= 0x1F; + one_wire(data); + wait_us(100); + + data = 0x00; + data |= 0x50; + one_wire(data); + data |= (((c & 0x0F) << 4) >> 4); + one_wire(data); + data &= 0x1F; + one_wire(data); + wait_us(100); + +} + +void lcd_command(unsigned char c) +{ + unsigned char data; + data = 0x00; + data |=0x40; + one_wire(data); + data |= ((c & 0xF0)>>4); + one_wire(data); + data &= 0x0F; + one_wire(data); + wait_us(100); + + data = 0x00; + data |= 0x40; + one_wire(data); + data |= (((c & 0x0F) << 4) >> 4); + one_wire(data); + data &= 0x0F; + one_wire(data); + wait_us(100); + +} + +void lcd_clear(void) +{ + lcd_command(0x1); + wait_ms(2); +} + +void lcd_position(unsigned char x,unsigned char y) +{ + if(x==1) + lcd_command(0x80+((y-1)%20)); + else + lcd_command(0xC0+((y-1)%20)); +} + +void lcd_printf(const char * a) +{ + wait_us(100); + while(*a) + lcd_putc(*a++); +} + +void lcd_init() +{ + one_wire(0); + wait_ms(15); + lcd_command(0x02); + wait_ms(2); + lcd_command(40); //2line 4bit + lcd_command(6); //write right + lcd_command(12); //pointer hidden + lcd_clear(); + + + lcd_command(128); //first line + +} + +
diff -r 000000000000 -r 9245c05647c9 1wire_lcd.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/1wire_lcd.h Tue Feb 22 10:41:38 2011 +0000 @@ -0,0 +1,16 @@ +#ifndef MBED_1wire_lcd_H +#define MBED_1wire_lcd_H + +#include "mbed.h" +#include "LPC1768/LPC17xx.h" + + +void one_wire(unsigned char data); +void lcd_putc(unsigned char); +void lcd_clear(void); +void lcd_printf(const char * a); +void lcd_position(unsigned char x, unsigned char y); +void lcd_command(unsigned char a); +void lcd_init(void); + +#endif \ No newline at end of file