单片机C语言程序2.docVIP

  • 2
  • 0
  • 约6.78千字
  • 约 7页
  • 2015-08-23 发布于河南
  • 举报
#include?reg52.h ?? #define?uint?unsigned?int ?? #define?uchar?unsigned?char ?? ?? sbit?lcdrs?=?P1^0; ?? sbit?lcdrw?=?P1^1; ?? sbit?lcden?=?P1^2; ?? ?? sbit?key0?=?P2^0;//功能键,选择时分秒 ?? sbit?key1?=?P2^1;//加1键 ?? sbit?key2?=?P2^2;//减1键 ?? sbit?key4?=?P2^4; ?? ?? uchar?key0_count;//按键0被按的次数(0~3) ?? ?? char?hour,minute,second;?//时分秒 ?? uint?timer_count;??//定时器中断计数 ?? ?? uchar?table_date[]?=?2009-4-12??Mon; ?? uchar?table_time[]?=?00:00:00; ?? ?? /******?函数申明?********/?? void?write_cmd_1602(uchar?cmd); ?? void?write_data_1602(uchar?dat); ?? void?write_add(uchar?add,uchar?dat); ?? void?init1602(); ?? void?delay(uint?z); ?? uchar?reverse(uchar?c); ?? void?keyscan(); ?? void?init(); ?? /******?主函数?********/?? void?main() ?? { ?? ????init(); ?? ????//init1602(); ?? ????//while(1); ?? ????while(1) ?? ????{ ?? ????????keyscan(); ?? ????????delay(5); ?? ????} ?? } ?? //1602液晶初始化 ?? void?init1602() ?? { ?? ????lcdrw?=?0;?????????????//本程序只读不写,故将其置低 ?? ????lcden?=?0;?????????????//关闭1602 ?? ????delay(5); ?? ????write_cmd_1602(0x01);??//清屏 ?? ????write_cmd_1602(0x38);??//显示模式 ?? ????write_cmd_1602(0x0c);??//开显示,不显示光标,不闪烁 ?? ????write_cmd_1602(0x06);??//地址指针自动加1 ?? ????write_cmd_1602(0x80+1);//将光标指向第一行第二个位置 ?? ????delay(5); ?? } ?? void?delay(uint?z) ?? { ?? ????uint?x,y; ?? ????for(x=z;x0;x--) ?? ????????for(y=110;y0;y--); ?? } ?? /**?将发送的数据进行翻转,高位到低位,低位转到高位?**/??? ?? uchar?reverse(uchar?c)??? ?? {??? ?? ???uchar?chbuff=0;??? ?? ???if?(c0x01)?chbuff=chbuff|0x80;??? ?? ???if?(c0x02)?chbuff=chbuff|0x40;??? ?? ???if?(c0x04)?chbuff=chbuff|0x20;??? ?? ???if?(c0x08)?chbuff=chbuff|0x10;??? ?? ???if?(c0x10)?chbuff=chbuff|0x08;??? ?? ???if?(c0x20)?chbuff=chbuff|0x04;??? ?? ???if?(c0x40)?chbuff=chbuff|0x02;??? ?? ???if?(c0x80)?chbuff=chbuff|0x01;??? ?? ???return?chbuff;??? ?? } ?? //向液晶写命令 ?? void?write_cmd_1602(uchar?cmd) ?? { ?? ????lcdrs?=?0;?//低表示写命令,高表示写数据 ?? ????delay(5); ?? ????P0?=?reverse(cmd); ?? ????delay(5); ?? ????lcden?=?1;?//给一个高脉冲 ?? ????delay(5);??? ?? ????lcden?=?0; ?? ????

文档评论(0)

1亿VIP精品文档

相关文档