51单片机经典C程序(1602)

相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

ET0=HIGH; TR0=HIGH; LCD_init();
} /*********************************************************************** /******************************** I2C PART **************************/ void I2C_delay(void) { _nop_();_nop_();_nop_();_nop_(); } /*********************************************************************** void I2C_start(void) { SDA=HIGH; _nop_(); SCLK=HIGH; _nop_(); SDA=LOW; _nop_(); SCLK=LOW; _nop_(); } /*********************************************************************** void I2C_stop(void) { SDA=LOW; _nop_(); SCLK=HIGH; _nop_(); SDA=HIGH; _nop_(); SCLK=LOW; _nop_(); } /*********************************************************************** void I2C_send_ack(bit k)
{ SDA=k; I2C_delay(); SCLK=HIGH; I2C_delay(); SCLK=LOW;
} /*********************************************************************** void I2C_write_byte(unsigned char dat) { unsigned char i; for (i=8;i>0;i--) { SCLK=LOW; I2C_delay(); SDA=(bit)(dat&MSB); dat<<=1; I2C_delay(); SCLK=HIGH; I2C_delay(); } SCLK=LOW; } /*********************************************************************** unsigned char I2C_read_byte(void) { unsigned char i,dat; for (i=0;i<8;i++) { SCLK=LOW; I2C_delay(); SDA=HIGH; I2C_delay(); SCLK=HIGH; dat<<=1; I2C_delay();
if(SDA) dat++; } SCLK=LOW; return (dat);
} /*********************************************************************** /************************ 24C02 PART **********************************/ void AT24C02_write(unsigned char address,unsigned char dat) { unsigned char temp; temp=dat/10; temp<<=4; temp=dat%10+temp; I2C_start(); I2C_write_byte(WRITE24C02); I2C_send_ack(ACK); I2C_write_byte(address); I2C_send_ack(ACK); I2C_write_byte(temp); I2C_send_ack(NO_ACK); I2C_stop();
AT24C02 C语言驱动程序—LCD1602 显示
程序匠人 发表于 2006-4-5 22:31:00 阅读全文 | 回复(1) | 引用通告 AT24C02 C语言驱动程序—LCD1602 显示 -|zl0801 发表于 2005-8-25 9:21:00 //AT24C02 EEPROM drive program //for 51 mcu with lcd1602 as display //designed by zhaoliang //2005-6-14 21:02 #i nclude " reg51.h " #i nclude " intrins.h " /********************************************************************/ //lcd part #define LINE1 0 #define LINE2 1 #define LINE1_HEAD 0x80 #define LINE2_HEAD 0xC0 #define LCD_DELAY_TIME 40 #define DATA_MODE 0x38 #define OPEN_SCREEN 0x0C #define DISPLAY_ADDRESS 0x80 #define CLEARSCREEN LCD_en_command(0x01) //common part #define HIGH 1 #define LOW 0 #define TRUE 1 #define ZERO 0 //at24c02 part #define WRITE24C02 0xA0 #define READ24C02 0xA1 //I2C part #define ACK 0 #define NO_ACK 1 #define MSB 0x80 /********************************************************************/ //change this part at different board
Hale Waihona Puke Baidu
unsigned char temp; Mcu_init(); while(1) { AT24C02_write(0x00,count[1]); temp=AT24C02_read(0x00); LCD_write_string(0x00,LINE1,"AT24C02 TEST"); LCD_write_char(0x0e,LINE1,(temp/10)|0x30); LCD_write_char(0x0f,LINE1,(temp%10)|0x30); LCD_write_string(0x00,LINE2,"TIMER0 JISHU"); LCD_write_char(0x0e,1,(count[1]/10)|0x30); LCD_write_char(0x0f,1,(count[1]%10)|0x30); AT24C02_write(0x00,count[1]); }
#define LCDIO P2 sbit LCD1602_RS=P0^7; //data command select 1 data 0 command pin 4 sbit LCD1602_RW=P0^6; //read write select 1 read 0 write pin 5 sbit LCD1602_EN=P0^5; //LCD enable signal pin 6 sbit SDA=P2^3; //AT24C02 serial data pin 5 sbit SCLK=P2^2; //AT24C02 serial clock pin 6 /********************************************************************/ void LCD_delay(void);//lcd delay function void LCD_en_command(unsigned char command);//write command function void LCD_en_dat(unsigned char temp);//write data function void LCD_set_xy( unsigned char x, unsigned char y );//set display addres function void LCD_write_char( unsigned x,unsigned char y,unsigned char dat);//write lcd a character function void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s);//write lcd string function void LCD_init(void);//lcd initize function /********************************************************************/ void I2C_delay(void);//I2C delay function void I2C_start(void);//I2C start function void I2C_stop(void);//I2C stop function void I2C_send_ack(bit k);//I2C send responsion function void I2C_write_byte(unsigned char dat);//I2C bus write byte function unsigned char I2C_read_byte(void);//I2C bus read byte function /********************************************************************/ void AT24C02_write(unsigned char address,unsigned char dat);//write 24c0 information function unsigned char AT24C02_read(unsigned char address);//read 24c02 information function /********************************************************************/ void Mcu_init(void);//system initize funcition void delay_nms(unsigned int n);//delay functinon unsigned char count[2]; /********************************************************************/ void main() {
} /*********************************************************************** void timer0(void) interrupt 1 using 1 { TH0=-(12000/256); TL0=-(12000%256); count[0]=count[0]+1; if(count[0]==100) { count[0]=0; count[1]=count[1]+1; if(count[1]==99) count[1]=0; } } /*********************************************************************** void Mcu_init(void) { TMOD=0x11; TH0=-(12000/256); TL0=-(12000%256); EA=HIGH;
相关文档
最新文档