I write a small code in C to drive LCD ht1621 and it seemd OK but I can only write but not read.Although I set bit P1.6 to make it read OK but I can not get the data from LCD. I write a small code in ASM and i can both read and write. Could you tell me how to read from pin? I include my C code and I need your help #include<reg51.h> #include<intrins.h> #define READ_ID 0xC0 #define WRITE_ID 0xA0 #define COMMAND_ID 0x80 #define SYS_DIS 0x00 #define SYS_EN 0x01 #define LCD_OFF 0x02 #define LCD_ON 0x03 volatile unsigned char idata m _at_ 0x56; volatile unsigned char idata n _at_ 0x57; volatile unsigned char idata dt _at_ 0x58; sbit C=P3^3; sbit W=P3^4; sbit R=P3^2; sbit DATA=P3^5; sbit IRQ=P1^6; sbit SCL=P1^5; sbit SDA=P1^4; void delay() { _nop_(); _nop_(); _nop_(); } void start() { C=0; _nop_(); _nop_(); } void stop() { C=1; _nop_(); _nop_(); } void send_id(unsigned char c) { unsigned char i; for(i=3;i>0;i--) { W=0; _nop_(); _nop_(); _nop_(); if((c&0x80)==0x80) DATA=1; else DATA=0; W=1; _nop_(); _nop_(); _nop_(); c=c<<1; } } void send_command(unsigned char c) { unsigned char i; start(); send_id(COMMAND_ID); for(i=9;i>0;i--) { W=0; _nop_(); _nop_(); _nop_(); if((c&0x80)==0x80) DATA=1; else DATA=0; W=1; _nop_(); _nop_(); _nop_(); c=c<<1; } stop(); } void send_address(unsigned char c) { unsigned char i; for(i=2;i>0;i--) { c=c<<1; } for(i=6;i>0;i--) { W=0; _nop_(); _nop_(); _nop_(); if((c&0x80)==0x80) DATA=1; else DATA=0; W=1; _nop_(); _nop_(); _nop_(); c=c<<1; } } void read_byte() { unsigned char c; for(c=4;c>0;c--) { R=0; delay(); R=1; delay(); if(DATA) { dt|=0x80; } dt>>=1; } } void read_data() { start(); send_id(READ_ID); send_address(32); read_byte(); stop(); } void send_data(unsigned char c) { unsigned char i; for(i=4;i>0;i--) { W=0; _nop_(); _nop_(); _nop_(); if((c&0x80)==0x80) DATA=1; else DATA=0; W=1; _nop_(); _nop_(); _nop_(); c=c<<1; } } void display_data() { start(); send_id(WRITE_ID); send_address(m); send_data(n); stop(); delay(); } void clear() { unsigned char i; start(); send_id(WRITE_ID); send_address(0x00); for(i=128;i>0;i--) { W=0; _nop_(); _nop_(); _nop_(); DATA=0; W=1; _nop_(); _nop_(); _nop_(); } stop(); } void main() { unsigned char c; send_command(SYS_EN); send_command(43); send_command(LCD_ON); clear(); EA = 0; m=32; n=0x80; display_data(); c=read_data(); while(1) { } }
There's a few mistakes here: firstly: the title "somebody helps me!" is not very descriptive - try something like 'problem with lcd" secondly: no toolset was selected - but we can figure from your code it is C51. Thirdly: I have no idea how you hardware is interfaced. Your code has me confused. If you have it working with assembler, there's something you're not doing in 'C'. I think you're the only one who can figure this one out. Why are you declaring absolute memory locations?? Not a good idea even if you are mixing assmebler with 'C'. You need to give us more information if you want help.
"I write a small code in ASM and i can both read and write." So why bother with 'C'??? Just call your working assembler from 'C'!! http://www.keil.com/forum/docs/thread4984.asp