| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 644 人关注过本帖
标题:大家帮忙看看吧,主程序要怎么改啊。。谢谢了~
取消只看楼主 加入收藏
勒挂
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2012-6-26
结帖率:33.33%
收藏
已结贴  问题点数:20 回复次数:0 
大家帮忙看看吧,主程序要怎么改啊。。谢谢了~

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 interfac
            
sbit LCD_RS=P2^6;             //LCD control pins  
sbit LCD_RW=P0^5;
sbit LCD_EN=P2^0;

sbit key=P1^3;



int a=0;

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++);
    }
}
uchar delay(uint z)               //delay for z ms
{
    uint x,y;
    for(x=z;x>0;x--)
    for(y=100;y>0;y--);
    return a;
}
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_DATA=0;
    lcd_com(0x38);         //LCD initialized 8-bit interface
    delay(10);
    lcd_com(0x38);         //LCD initialized 8-bit interface
    delay(10);
    lcd_com(0x38);         //LCD initialized 8-bit interface
    delay(10);
              
    lcd_com(0x0c);  delay(5);          //display on, cursor off
    lcd_com(0x06);  delay(5);        //cursor moving direction
    lcd_com(0x01);  delay(5);         //clear display            
    lcd_com(0x02);  delay(5);         //cursor home         
}
void main()
{
   
    LCD_RS=0;
    LCD_EN=0;
    init();

    PORT_Init();
     

         while(1)
    {
         
          if(key!=1)               //button pressed
        {
                        
           while(key!=1);
           {                    //wait for button to be released
            a++;              //count the times of button pressed
                    
              if(a==1)          //button pressed in first time
              {
                lcd_com(0x80);
                delay(100);                                             
                lcd_msg1("Time=0");
                delay(100);
              }
              a=1;
            }
          }
         if(key!=1)
         {
           
            while(key!=1);
            {
               if(a==2)         //button pressed in second time   
               {
                 lcd_com(0x80);
                  delay(100);                                                
                 lcd_msg1("Time=1");
                 delay(100);
                }
                  a=2;
            }
          }
          if(key!=1)
         {
         
            while(key!=1);
            {
               if(a==3)             //button pressed in third time
               {
                 lcd_com(0x80);
                 delay(100);                                                
                 lcd_msg1("Time=2");
                 delay(100);
                }
                  a=3;
            }
          }
     
    }  

}

   


void PORT_Init (void)
{
  PRT1CF |= 0x08;
  
 }

 
搜索更多相关主题的帖子: 时间 control include 主程序 
2012-07-04 11:38
快速回复:大家帮忙看看吧,主程序要怎么改啊。。谢谢了~
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017060 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved