51單片機總線驅(qū)動
全部源代碼下載:http://www.51hei.com/f/128yhj.rar
#include"reg51.h"sbit cd = P2^0;unsigned char pdata *addr;#define uchar unsigned char#define uint unsigned shortvoid lcd_writecom_two(uchar onedat,uchar twodat,uchar com);void lcd_writedat_onebyte(uchar onedat,uchar com);uchar lcd_readdat_onebyte(uchar com);void lcd_writedat_nbyte(uchar *dat,uchar len);void lcd_readdat_nbyte(uchar *dat ,uchar len);void clear_point(uchar x,uchar y);void sel_point(uchar x,uchar y);void sel_rmiddling(uchar x,uchar y);void clr_rmiddling(uchar x,uchar y);void sel_rbig(uchar x,uchar y);void clr_rbig(uchar x,uchar y);void graph_mode_writeword(uchar x,uchar y,uchar *dat);void graph_mode_write_letter(uchar x,uchar y,uchar *dat);void rhorizontal(uchar x0,uchar x1,uchar y);void erect(uchar y0,uchar y1,uchar x);void Draw_line(uchar x0,uchar y0,uchar x1,uchar y1);void draw_circle(int x, int y, int r);void lcd_init();/**********************************讀取lcd狀態(tài)**********************************/uchar lcd_readcom(){uchar temp;cd=1;addr = 0xff;temp = *addr;return temp;}/*********************************判斷指令/數(shù)據(jù)讀寫忙碌狀態(tài)*********************************/void check_busy(){uchar temp;do{temp=lcd_readcom();}while((temp&0x03)!=0x03);}/*********************************判斷數(shù)據(jù)自動寫忙碌狀態(tài)*********************************/void check_auto_write_busy(){uchar temp;do{temp=lcd_readcom();}while((temp&0x08)!=0x08);}/*********************************判斷數(shù)據(jù)自動讀忙碌狀態(tài)*********************************/void check_auto_read_busy(){uchar temp;do{temp=lcd_readcom();}while((temp&0x04)!=0x04);}/*********************************向lcd寫命令*********************************/void lcd_writecom(uchar dat){check_busy();cd=1;*addr = dat;}/************************************向lcd寫數(shù)據(jù)************************************/void lcd_writedat(uchar dat){check_busy();cd=0;*addr = dat;}/********************************從lcd讀數(shù)據(jù)*********************************/uchar lcd_readdat(){uchar temp;cd=0;addr = 0xff;temp = *addr;return temp;}
評論