没弄明白啊~哪位好心人能帮我看看怎么改啊。。谢谢了呀
1.当按下按钮时,LCD显示为"time=0",再按一下时"time=1",依次递加到"time=24"当按24次时2.当确认某个时间时,按住按钮保持2秒以上,便可确认设置成功
3.LCD是8x2的,第一排可以显示"Set Time",第二排显示时间"time=0"
4.用的是单片机8051f226
//#include <reg52.h>
#include <c8051f200.h>
#define uchar unsigned char
#define uint unsigned int
#define LCD_DATA P3 //data port for LCD interface
sbit LCD_RS=P2^6; //LCD control pins
sbit LCD_RW=P0^5;
sbit LCD_EN=P2^0;
sbit key = P1^1;
sbit LCD=P1^7;
void delay(uint);
void lcd_com(uchar com); //LCD command code
void lcd_data(uchar da);
void PORT_Init (void); //ASCII character to be display on LCD
void init();
void lcd_msg1(char*msg)
{
char*pstr;
pstr=msg;
while(*pstr)
{
lcd_data(*pstr++);
}
}
void delay(uint z) //delay for z ms
{
uint x,y;
for(x=z;x>0;x--)
for(y=100;y>0;y--);
}
void lcd_com(uchar com) //8 bits interface,to LCD command
{
LCD_DATA=com;
LCD_RW=0;
LCD_RS=0;
LCD_EN=1;
delay(5);
LCD_EN=0;
}
void lcd_data(uchar da) //send a byte to LCD data port
{
LCD_DATA=da;
LCD_RW=0; //data byte sent to the data bus
LCD_RS=1;
LCD_EN=1;
delay(5);
LCD_EN=0;
}
void init()
{
lcd_com(0x38); //LCD initialized 8-bit interface
lcd_com(0x0c); //display on, cursor off
lcd_com(0x06); //cursor moving direction
lcd_com(0x01); //clear display
lcd_com(0x02); //cursor home
}
void main()
{
LCD_RW=0;
LCD_EN=0;
init();
while(1)
{
if(key==0)
{
LCD=1;
lcd_com(0x80);
lcd_msg1("Set Time");
delay(10);
lcd_com(0xc0);
lcd_msg1("Time=1");
delay(10);
}
if(key==1)
{
LCD=0;
}
}}
void PORT_Init (void)
{
PRT1CF |= 0x82;
}