这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » DIY与开源设计 » 电子DIY » 补交进程贴

共1条 1/1 1 跳转至

补交进程贴

菜鸟
2012-01-12 23:01:14     打赏

最近好多事,好多事,好多事啊 。。。




补交上次的时钟程序。。。。。
温度    时间  加闹钟


#include <reg52.h>
#include <intrins.h>

#define uchar unsigned char
#define uint unsigned int
#define TIMER1 0xf3
#define delayNOP() {_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;_nop_() ;}

sbit LCD_RS = P2^4 ;            
sbit LCD_RW = P2^5 ;  //
sbit LCD_EN = P2^6 ;  //
sbit DQ = P1^3  ;  //定义DS18B20端口DQ 
sbit P07=P0^7 ;    // 
sbit SCK=P3^6;  //时钟芯片控制引脚
sbit SDA=P3^4;  //时钟芯片的数据引脚
sbit RST=P3^5;  //DS1302复位引脚
sbit k=P3^3;  //测试引脚
sbit k1=P3^2;
sbit k2=P3^1;
sbit Speak =P1^0;  //蜂鸣器
bit flag,flag1;
code unsigned char write_rtc_address[7]={0x80,0x82,0x84,0x86,0x88,0x8a,0x8c}; //秒分时日月周年 最低位读写位
code unsigned char read_rtc_address[7]={0x81,0x83,0x85,0x87,0x89,0x8b,0x8d};
uchar lcd_miao[2]={0x00,0x00};
uchar lcd_fen[2]={0x00,0x00};
uchar lcd_shi[2]={0x00,0x00};
uchar lcd_ri[2]={0x00,0x00};
uchar lcd_nian[2]={0x00,0x00};
uchar lcd_yue[2]={0x00,0x00};
uchar lcd_zhou[2]={0x00,0x00};
uchar cshi[2]={0x00,0x00};
uchar cfen[2]={0x00,0x00};
unsigned char data  temp_data[2] = {0x00,0x00} ;  //wendu
unsigned char data  display[5] =   {0x00,0x00,0x00,0x00,0x00} ;
unsigned char code  ditab[16] =    {0x00,0x01,0x01,0x02,0x03,0x03,0x04,0x04,
                                                        0x05,0x06,0x06,0x07,0x08,0x08,0x09,0x09} ;
unsigned char code SONG[] ={      //祝你平安
0x26,0x20,0x20,0x20,0x20,0x20,0x26,0x10,0x20,0x10,0x20,0x80,0x26,0x20,0x30,0x20,
0x30,0x20,0x39,0x10,0x30,0x10,0x30,0x80,0x26,0x20,0x20,0x20,0x20,0x20,0x1c,0x20,
0x20,0x80,0x2b,0x20,0x26,0x20,0x20,0x20,0x2b,0x10,0x26,0x10,0x2b,0x80,0x26,0x20,
0x30,0x20,0x30,0x20,0x39,0x10,0x26,0x10,0x26,0x60,0x40,0x10,0x39,0x10,0x26,0x20,
0x30,0x20,0x30,0x20,0x39,0x10,0x26,0x10,0x26,0x80,0x26,0x20,0x2b,0x10,0x2b,0x10,
0x2b,0x20,0x30,0x10,0x39,0x10,0x26,0x10,0x2b,0x10,0x2b,0x20,0x2b,0x40,0x40,0x20,
0x20,0x10,0x20,0x10,0x2b,0x10,0x26,0x30,0x30,0x80,0x18,0x20,0x18,0x20,0x26,0x20,
0x20,0x20,0x20,0x40,0x26,0x20,0x2b,0x20,0x30,0x20,0x30,0x20,0x1c,0x20,0x20,0x20,
0x20,0x80,0x1c,0x20,0x1c,0x20,0x1c,0x20,0x30,0x20,0x30,0x60,0x39,0x10,0x30,0x10,
0x20,0x20,0x2b,0x10,0x26,0x10,0x2b,0x10,0x26,0x10,0x26,0x10,0x2b,0x10,0x2b,0x80,
0x18,0x20,0x18,0x20,0x26,0x20,0x20,0x20,0x20,0x60,0x26,0x10,0x2b,0x20,0x30,0x20,
0x30,0x20,0x1c,0x20,0x20,0x20,0x20,0x80,0x26,0x20,0x30,0x10,0x30,0x10,0x30,0x20,
0x39,0x20,0x26,0x10,0x2b,0x10,0x2b,0x20,0x2b,0x40,0x40,0x10,0x40,0x10,0x20,0x10,
0x20,0x10,0x2b,0x10,0x26,0x30,0x30,0x80,0x00,
                                  //路边的野华不要采
0x30,0x1C,0x10,0x20,0x40,0x1C,0x10,0x18,0x10,0x20,0x10,0x1C,0x10,0x18,0x40,0x1C,
0x20,0x20,0x20,0x1C,0x20,0x18,0x20,0x20,0x80,0xFF,0x20,0x30,0x1C,0x10,0x18,0x20,
0x15,0x20,0x1C,0x20,0x20,0x20,0x26,0x40,0x20,0x20,0x2B,0x20,0x26,0x20,0x20,0x20,
0x30,0x80,0xFF,0x20,0x20,0x1C,0x10,0x18,0x10,0x20,0x20,0x26,0x20,0x2B,0x20,0x30,
0x20,0x2B,0x40,0x20,0x20,0x1C,0x10,0x18,0x10,0x20,0x20,0x26,0x20,0x2B,0x20,0x30,
0x20,0x2B,0x40,0x20,0x30,0x1C,0x10,0x18,0x20,0x15,0x20,0x1C,0x20,0x20,0x20,0x26,
0x40,0x20,0x20,0x2B,0x20,0x26,0x20,0x20,0x20,0x30,0x80,0x20,0x30,0x1C,0x10,0x20,
0x10,0x1C,0x10,0x20,0x20,0x26,0x20,0x2B,0x20,0x30,0x20,0x2B,0x40,0x20,0x15,0x1F,
0x05,0x20,0x10,0x1C,0x10,0x20,0x20,0x26,0x20,0x2B,0x20,0x30,0x20,0x2B,0x40,0x20,
0x30,0x1C,0x10,0x18,0x20,0x15,0x20,0x1C,0x20,0x20,0x20,0x26,0x40,0x20,0x20,0x2B,
0x20,0x26,0x20,0x20,0x20,0x30,0x30,0x20,0x30,0x1C,0x10,0x18,0x40,0x1C,0x20,0x20,
0x20,0x26,0x40,0x13,0x60,0x18,0x20,0x15,0x40,0x13,0x40,0x18,0x80,0x00,

};
unsigned char code  mytab[8] = {0x0C,0x12,0x12,0x0C,0x00,0x00,0x00,0x00} ;   //  *****  0x0c  -----*  **   可用于自定义字符
uchar dis1[]={"DATE:     -  -  "};             //  *****  0x12  ----- ** *   
uchar dis2[]={"T:       :  :  "};             //  *****
uchar code cdis1[]={"JZD MCUDIY"} ;             //  *****
uchar code cdis2[]={"  TEM:     .  C"} ;           //  *****
uchar code tdis[]={"Clock set:"};
uchar code tdis1[]={"  :  "};
uchar dsdat,gb=6,gb1=0x0b;
uchar qn=2,bn=0;
uchar Count,flag_c;
//********************************************************
//  中断初始化
//********************************************************
void Time0_Init()
{
 TMOD = 0x01;
 EA = 1;
 ET0 = 1;
 TH0  = 0xB1;    //B1
 TL0  = 0xDF;    //DF
}
//*******************************************************
//    中断子程序                  //  *****
//*******************************************************
void Time0_Int() interrupt 1
{
 TH0 = 0xB1;
 TL0 = 0xDF;
 Count++;   //长度加1
}
//*******************************************************
/********************************************************************
* 名称 : Delay_xMs()
* 功能 : 延时子程序    ----蜂鸣器
* 输入 : x
* 输出 : 无
***********************************************************************/
void Delay_xMs(uint x)
{
    uint i,j;
    for(i=0; i<x; i++)
    {
        for(j=0; j<7; j++);
    }
}
///*****************************************************
//  延时  
//
//  
//*******************************************************
void delay1(int ms)       //
{
 unsigned char y ;
 while(ms--)
 {
  for(y = 0 ; y<250 ; y++)
  {
   _nop_() ;
   _nop_() ;
   _nop_() ;
   _nop_() ;
   _nop_() ;
   _nop_() ;
   _nop_() ;
   _nop_() ; 
  }
 }
}
void Delay(unsigned int num)
{
  while( --num ) ;
}

//*******************************************************
void UartInit(void)
{
 ET1 =0;    //禁止1允许
 ES =0;    //禁止中断允许
 SCON = 0x50;  //串口方式1,允许接收
 TMOD |= 0x20;  //定时器1工作方式2,定时器0工作方式1
 PCON |= 0X80;  //9600
 TH1 = TIMER1; 
 TL1 = TIMER1; 
 TR1 = 1;  //启动定时器1
}
//*******************************************************
void sendch(unsigned char dat)
{
 TI=0;
 SBUF=dat;
 while(!TI);
 TI=0;
}
//*******************************************************
/******************************************************************/
/*检查LCD忙状态                                                   */
/*lcd_busy为1时,忙,等待。lcd-busy为0时,闲,可写指令与数据。   */
/******************************************************************/
bit lcd_busy()
{                         
    bit result =0;
 P07 =1;      //    必须加P07=1 
    LCD_RS = 0 ;
    LCD_RW = 1 ;
    LCD_EN = 1 ;
    delayNOP();
    result = (bit)(P0&0x80) ;
    LCD_EN = 0 ;
    return(result) ;
}

/*写指令数据到LCD                                                  */
/*RS=L,RW=L,E=高脉冲,D0-D7=指令码。          */
/*******************************************************************/
void lcd_wcmd(uchar cmd)
{                         
 while(lcd_busy()) ;
    LCD_RS = 0 ;
    LCD_RW = 0 ;
    LCD_EN = 0 ;
    _nop_() ;
    _nop_() ;
    P0 = cmd ;
    delayNOP() ;
    LCD_EN = 1 ;
    delayNOP() ;
    LCD_EN = 0 ; 
}

/*******************************************************************/
/*写显示数据到LCD                            */
/*RS=H,RW=L,E=高脉冲,D0-D7=数据。       */
/*******************************************************************/
void lcd_wdat(uchar dat)
{                         
 while(lcd_busy()) ;
    LCD_RS = 1 ;
    LCD_RW = 0 ;
    LCD_EN = 0 ;
    P0 = dat ;
    delayNOP() ;
    LCD_EN = 1 ;
    delayNOP() ;
    LCD_EN = 0 ;
}


/*  LCD初始化设定                                                  */
/*******************************************************************/
void lcd_init(void)
{
 delay1(20) ;      //delay  3ms
 lcd_wcmd(0x01) ;        //清除LCD的显示内容           
 lcd_wcmd(0x38) ;        //16*2显示,5*7点阵,8位数据
 delay1(10) ;   //delay2ms
 lcd_wcmd(0x38) ;        
 delay1(10) ;
 lcd_wcmd(0x38) ;        
 delay1(10) ;   // delay2ms

 lcd_wcmd(0x0c) ;       //显示开,关光标
 delay1(10) ;
 lcd_wcmd(0x06) ;       //移动光标 地址自加1
 delay1(10) ;
 lcd_wcmd(0x01) ;       //清除LCD的显示内容
 delay1(10);
}
/*  设定显示位置                                    */
/*******************************************************************/
void lcd_pos(uchar pos)
{                         
  lcd_wcmd(pos|0x80) ;  //数据指针=80+地址变量
}

/*自定义字符写入CGRAM                                   */
/*******************************************************************/
void writetab(void) 

    unsigned char i ;
    lcd_wcmd(0x40) ;            //写CGRAM
    for (i=0;i<8;i++)      
    lcd_wdat(mytab[i]) ;    
}

/*LCD初始化显示                                           */
/*******************************************************************/
void lcd_sta(void)
{
 uchar m=0;
 lcd_init();
 lcd_pos(0);
 while(dis1[m]!='\0')
 {
  lcd_wdat(dis1[m]);
  m++;
 }
 m=0;
 lcd_pos(0x40);
 while(dis2[m]!='\0')
 {
  lcd_wdat(dis2[m]);
  m++;
 }
 m=0;
}
//******************************************************************
// 写  时钟芯片 一个字节  
//*******************************************************************
void Write_Ds1302_Byte(unsigned char temp)    //
{
 unsigned char i;
 for(i=0;i<8;i++)
 {
  SCK=0;
  SDA=temp&0x01;
  SCK=1;
  temp>>=1;
 }
}
//*******************************************************************
//在时钟芯片的寄存器,指定地址写入字节数据
//*******************************************************************
void Write_Ds1302(unsigned char address,unsigned char dat )
{
 RST=0;
 _nop_();
 SCK=0;
 _nop_();
 RST=1;
 _nop_();
 _nop_();
 _nop_();
 Write_Ds1302_Byte(address);
 Write_Ds1302_Byte(dat);
 RST=0;
}
//********************************************************************
//********************************************************************
// 读取时钟芯片指定地址的寄存器的字节数据    包括年月日时分秒
// 对时钟芯片进行写操作前,WP位必须先写为0,即8E h寄存器的Bit7 写为0,才能进行其他寄存器的写操作
//******************************************************************
unsigned char Read_Ds1302(unsigned char address)
{
 unsigned char i,temp=0x00;
 RST=0;
 _nop_();
 SCK=0;
 _nop_();
 RST=1;
 _nop_();
 _nop_();
 _nop_();
 Write_Ds1302_Byte(address);
 for(i=0;i<8;i++)
 {  
  SCK=1;
  SCK=0;
  temp>>=1;
  if(SDA)
  temp|=0x80;
//  SCK=0;
//  SCK=1;
 }
 RST=0;
 _nop_();
 RST=0;    //??
 SCK=0;
 _nop_();
 SCK=1;
 _nop_();
 SDA=0;
 _nop_();
 SDA=1;
 _nop_();
 return(temp);
}
//***************************************************************
//   星期X  显示
//********************************************************
void dis_zhou(uchar w)
{
 switch (w)
 {
  case 1:
  {
   lcd_pos(0x43);
   lcd_wdat('M');
   lcd_wdat('O');
   lcd_wdat('N');
   break;
  }
  case 2:
  {
   lcd_pos(0x43);
   lcd_wdat('T');
   lcd_wdat('U');
   lcd_wdat('E');
   break;
  }
  case 3:
  {
   lcd_pos(0x43);
   lcd_wdat('W');
   lcd_wdat('E');
   lcd_wdat('D');
   break;
  }
  case 4:
  {
   lcd_pos(0x43);
   lcd_wdat('T');
   lcd_wdat('H');
   lcd_wdat('U');
   break;
  }
  case 5:
  {
   lcd_pos(0x43);
   lcd_wdat('F');
   lcd_wdat('R');
   lcd_wdat('I');
   break;
  }
  case 6:
  {
   lcd_pos(0x43);
   lcd_wdat('S');
   lcd_wdat('A');
   lcd_wdat('T');
   break;
  }
  case 7:
  {
   lcd_pos(0x43);
   lcd_wdat('S');
   lcd_wdat('U');
   lcd_wdat('N');
   break;
  }
  default: break;
 }
}
//********************************************************************
void dslcd(void)
{
// uchar bn=0;
// uchar qn=2;
//************************************
 lcd_miao[1]=Read_Ds1302(read_rtc_address[0]);
 lcd_miao[0]=Read_Ds1302(read_rtc_address[0]);
 lcd_miao[1]>>=4;
 lcd_miao[0]&=0x0f;
//************************************
 lcd_fen[1]=Read_Ds1302(read_rtc_address[1]);
 lcd_fen[0]=Read_Ds1302(read_rtc_address[1]);
 lcd_fen[1]>>=4;
 lcd_fen[0]&=0x0f;
//************************************ 
 lcd_shi[1]=Read_Ds1302(read_rtc_address[2]);
 lcd_shi[0]=Read_Ds1302(read_rtc_address[2]);
 lcd_shi[1]>>=4;
 lcd_shi[0]&=0x0f;
//************************************
 lcd_ri[1]=Read_Ds1302(read_rtc_address[3]);
 lcd_ri[0]=Read_Ds1302(read_rtc_address[3]);
 lcd_ri[1]>>=4;
 lcd_ri[0]&=0x0f;
//************************************
 lcd_yue[1]=Read_Ds1302(read_rtc_address[4]);
 lcd_yue[0]=Read_Ds1302(read_rtc_address[4]);
 lcd_yue[1]>>=4;
 lcd_yue[0]&=0x0f;
//***********************************
 lcd_zhou[1]=Read_Ds1302(read_rtc_address[5]);
 lcd_zhou[0]=Read_Ds1302(read_rtc_address[5]);
 lcd_zhou[1]>>=4;
 lcd_zhou[0]&=0x0f;
//****************************************
 lcd_nian[1]=Read_Ds1302(read_rtc_address[6]);
 lcd_nian[0]=Read_Ds1302(read_rtc_address[6]);
 lcd_nian[1]>>=4;
 lcd_nian[0]&=0x0f;
//***********************************
 lcd_pos(0x4D);
 lcd_wdat(lcd_miao[1]+0x30);
 lcd_wdat(lcd_miao[0]+0x30);
 lcd_pos(0x4a);
 lcd_wdat(lcd_fen[1]+0x30);
 lcd_wdat(lcd_fen[0]+0x30);
 lcd_pos(0x47);
 lcd_wdat(lcd_shi[1]+0x30);
 lcd_wdat(lcd_shi[0]+0x30);
 lcd_pos(0x43);
 dis_zhou(lcd_zhou[0]);
 lcd_pos(0x0E);
 lcd_wdat(lcd_ri[1]+0x30);
 lcd_wdat(lcd_ri[0]+0x30);
 lcd_pos(0x0B);
 lcd_wdat(lcd_yue[1]+0x30);    //YUE shiwei 
 lcd_wdat(lcd_yue[0]+0x30);    //YUE gewei
 lcd_pos(0x08);
 lcd_wdat(lcd_nian[1]+0x30);
 lcd_wdat(lcd_nian[0]+0x30);
 lcd_pos(0x06);
 lcd_wdat(qn+0x30);
 lcd_wdat(bn+0x30);
 
}
/*******************************************************************/
bit Init_DS18B20(void)

  bit presence = 1;
     DQ = 1 ;      //DQ复位
     Delay(5) ;    //稍做延时  delay 3us

     DQ = 0 ;      //单片机将DQ拉低
     Delay(960) ;   //精确延时 大于 480us

     DQ = 1 ;       //拉高总线
     Delay(120) ;   //delay 60us

     if(DQ==0)     //如果=0则初始化成功 =1则初始化失败
     {
  presence=DQ;
//  sendch(0x01) ;
  }
  while(!DQ);
  Delay(960) ;
//   DQ = 1 ;
    
     return(presence) ; //返回信号,0=presence,1= no presence
}


/* 读一个字节                     */
/*******************************************************************/
unsigned char ReadOneChar(void)
{
 unsigned char i = 0 ;
 unsigned char dat = 0x00 ;
 DQ=1;
 Delay(960) ;
 for (i=0;i<8;i++)
   {
  DQ=0;
  dat>>=1;     //确保最高位为0,所以先移位
  Delay(4);
  DQ=1;
  Delay(4);
     if(DQ)dat|=0x80;
  Delay(120);

   }

     return (dat) ;
}

/* 写一个字节                                         */
/*******************************************************************/
void WriteOneChar(unsigned char dat)
{
 
 unsigned char i = 0 ;
// while(Init_DS18B20());
 DQ=1;
// Delay(100);
 for (i = 8;i > 0 ; i--)
 {
  if(dat&0x01)
  {
   DQ=0;
   Delay(8);
   DQ=1;
   Delay(150);
   DQ=1;
  }
  else
  {
   DQ=0;
   Delay(150);
   DQ=1;
  }
  Delay(8);
  dat>>=1;
 }
}

/* 读取温度                            */
/*******************************************************************/
void Read_Temperature(void)
{
     while(Init_DS18B20());
     
     WriteOneChar(0xCC);  // 跳过读序号列号的操作
     WriteOneChar(0x44);  // 启动温度转换
  delay1(10);
     while(Init_DS18B20());
     WriteOneChar(0xCC);  //跳过读序号列号的操作
     WriteOneChar(0xBE);  //读取温度寄存器
 
/* for(i=0;i<9;i++)
 {
  temp_data1[i]=ReadOneChar();
 }*/
 
     temp_data[0] = ReadOneChar();  //温度低8位
     temp_data[1] = ReadOneChar();   //温度高8位
}

 

/* 数据转换与温度显示                                              */
/*******************************************************************/
 void Disp_Temperature()
{
 display[4]=temp_data[0]&0x0f ;
 display[0]=ditab[display[4]]+0x30 ;             //查表得小数位的值
  
 display[4]=((temp_data[0]&0xf0)>>4)|((temp_data[1]&0x0f)<<4) ;
 display[3]=display[4]/100+0x30 ;
 display[1]=display[4]%100 ;
 display[2]=display[1]/10+0x30 ;
 display[1]=display[1]%10+0x30 ;
 if(display[3]==0x30)        //高位为0,不显示
 {
  display[3]=0x20 ;             
  if(display[2]==0x30)      //次高位为0,不显示
  display[2]=0x20 ;
 }

    lcd_pos(0x48) ;            
    lcd_wdat(display[3]) ;        //百位数显示
    lcd_pos(0x49) ;            
    lcd_wdat(display[2]) ;        //十位数显示
   lcd_pos(0x4a) ;            
    lcd_wdat(display[1]) ;        //个位数显示
   lcd_pos(0x4c) ;            
    lcd_wdat(display[0]) ;        //小数位数显示
}
//温度开始界面
//*********************************************************************
void Ok_Menu (void)
{
 uchar m;
 lcd_init();                //初始化LCD
 lcd_pos(0);                //设置显示位置为第一行的第1个字符
 m = 0;
// lcd_wdat('i');
// lcd_wdat('l');
 while(cdis1[m]!='\0')
 {                         //显示字符
  lcd_wdat(cdis1[m]);
  m++;
 }
 lcd_pos(0x40) ;             //设置显示位置为第二行第1个字符
 m = 0 ;
 while(cdis2[m] != '\0')
 {
  lcd_wdat(cdis2[m]) ;      //显示字符
  m++ ;
 }

 writetab() ;               //自定义字符写入CGRAM
 delay1(5) ;
 lcd_pos(0x4d) ;
 lcd_wdat(0x00) ;          //显示自定义字符
}
//****************************CLOCK***************SET**********************
void clock_set(void)
{
 uchar m;
 lcd_init();
 lcd_pos(0);
 m =0;
 while(tdis[m]!='\0')
 {
  lcd_wdat(tdis[m]);
  m++;
 }
 lcd_pos(0x44);
 m =0;
 while(tdis1[m]!='\0')
 {
  lcd_wdat(tdis1[m]);
  m++;
 }
 if(flag_c==1)
 {
  lcd_pos(0x0c);
  lcd_wdat('o');
  lcd_pos(0x0d);
  lcd_wdat('n');
  lcd_wdat(' ');
 }
 else
 {
  lcd_pos(0x0c);
  lcd_wdat('o');
  lcd_pos(0x0d);
  lcd_wdat('f');
  lcd_pos(0x0e);
  lcd_wdat('f');
 }
 lcd_pos(0x44);
 lcd_wdat(cshi[1]+0x30);
 lcd_pos(0x45);
 lcd_wdat(cshi[0]+0x30);
 lcd_pos(0x47);
 lcd_wdat(cfen[1]+0x30);
 lcd_pos(0x48);
 lcd_wdat(cfen[0]+0x30);
 while(flag1)
 {
  if(k==0)
  {
   delay1(10);
   if(k==0)
   {
    while(k==0);
    lcd_sta();
    flag1=0;
   }
  }
  if(k1==0)
  { 
   delay1(10);
   if(k1==0)
   {
    while(k1==0);
    gb1++;
    switch (gb1)
    {
     case 0x0d: gb1=0x44;break;
     case 0x46: gb1=0x47;break;
     case 0x49: gb1=0x0c;break;   //
     default: break;
    }
    lcd_pos(gb1);     //
    lcd_wcmd(0x0f);     //
   }
  }
  if(k2==0)
  {
   delay1(10);
   if(k2==0)
   {
    while(k2==0);
    if(gb1==0x0c)
    {
     if(flag_c==0)
     {
      lcd_pos(0x0c);
      lcd_wdat('o');
      lcd_pos(0x0d);
      lcd_wdat('n');
      lcd_wdat(' ');
      flag_c=1;
     }
     else
     {
      lcd_pos(0x0c);
      lcd_wdat('o');
      lcd_pos(0x0d);
      lcd_wdat('f');
      lcd_pos(0x0e);
      lcd_wdat('f');
      flag_c=0;
     }
    }
    if(gb1==0x44)
    {
     cshi[1]++;
     if(cshi[1]>=3)cshi[1]=0;
     lcd_pos(gb1);
     lcd_wdat(cshi[1]+0x30);
    }
    if(gb1==0x45)
    {
     cshi[0]++;
     if(cshi[0]>=10)cshi[0]=0;
     lcd_pos(gb1);
     lcd_wdat(cshi[0]+0x30);
    }
    if(gb1==0x47)
    {
     cfen[1]++;
     if(cfen[1]>=6)cfen[1]=0;
     lcd_pos(gb1);
     lcd_wdat(cfen[1]+0x30);
    }
    if(gb1==0x48)
    {
     cfen[0]++;
     if(cfen[0]>=10)cfen[0]=0;
     lcd_pos(gb1);
     lcd_wdat(cfen[0]+0x30);
    }
    lcd_pos(gb1);     //
    lcd_wcmd(0x0f);     //
   }
  }
 } 
}
//********************************************************************

//********************************************************************
void keyscan(void)
{
 if(k==0)
 {
  delay1(10);
  if(k==0)
  {
   while(k==0);
   
//    dsdat=Read_Ds1302(read_rtc_address[4]);
//    sendch(dsdat);
   Ok_Menu ();
   flag=1;
   while(flag)
   {
    Read_Temperature() ;
       Disp_Temperature() ;
    if(k==0)
    {
     delay1(10);
     if(k==0)
     {
      while(k==0);
      lcd_sta();
      flag=0;
      flag1=1;
     }
    }
   }
   clock_set();
   
  }
 }
 if(k1==0)
 {
  delay1(10);
  if(k1==0)
  {
   while(k1==0);
   lcd_pos(gb);
   lcd_wcmd(0x0f);
   while(1)
   {
    if(k==0)    //时间设置完毕  写入DS1302  跳出设置函数
    {
     delay1(10);
     if(k==0)
     { 
      while(k==0);
      lcd_wcmd(0x0c);
      Write_Ds1302(0x8C,(lcd_nian[1]<<=4)|lcd_nian[0]);
      Write_Ds1302(0x8a,(lcd_zhou[1]<<=4)|lcd_zhou[0]);
      Write_Ds1302(0x88,(lcd_yue[1]<<=4)|lcd_yue[0]);
      Write_Ds1302(0x86,(lcd_ri[1]<<=4)|lcd_ri[0]);
      Write_Ds1302(0x84,(lcd_shi[1]<<=4)|lcd_shi[0]);
      Write_Ds1302(0x82,(lcd_fen[1]<<=4)|lcd_fen[0]);
      Write_Ds1302(0x80,(lcd_miao[1]<<=4)|lcd_miao[0]);
      break;
     }
    }
    if(k1==0)
    {
     delay1(10);
     if(k1==0)
     { 
      while(k1==0);
      gb++;
      switch (gb)
      {
       case 0x0a: gb=0x0b;break;   // 光标移动
       case 0x0d: gb=0x0e;break;   // 
       case 0x10: gb=0x45;break;   //
       case 0x46: gb=0x47;break;
       case 0x49: gb=0x4a;break;   //
       case 0x4c: gb=0x4d;break;   //
       case 0x4f: gb=0x06;break;   //
       default: break;
      }
      lcd_pos(gb);
      lcd_wcmd(0x0f);
     }
    }
    if(k2==0)
    {
     delay1(10);
     if(k2==0)
     { 
      while(k2==0);
      if(gb==0x06)
      { 
       qn++;
       if(qn>=10)qn=0;
       lcd_pos(gb);
       lcd_wdat(qn+0x30);
       lcd_pos(gb);
      }
      if(gb==0x07)
      {
       bn++;
       if(bn>=10)bn=0;
       lcd_pos(gb);
       lcd_wdat(bn+0x30);
       lcd_pos(gb);
      }
      if(gb==0x08)
      {
       lcd_nian[1]++;
       if(lcd_nian[1]>=10)lcd_nian[1]=0;
       lcd_pos(gb);
       lcd_wdat(lcd_nian[1]+0x30);
       lcd_pos(gb);
      }
      if(gb==0x09)
      {
       lcd_nian[0]++;
       if(lcd_nian[0]>=10)lcd_nian[0]=0;
       lcd_pos(gb);
       lcd_wdat(lcd_nian[0]+0x30);
       lcd_pos(gb);
      }
      if(gb==0x0b)
      {
       lcd_yue[1]++;
       if(lcd_yue[1]>=2)lcd_yue[1]=0;
       lcd_pos(gb);
       lcd_wdat(lcd_yue[1]+0x30);
       lcd_pos(gb);
      }
      if(gb==0x0c)
      {
       lcd_yue[0]++;
       if(lcd_yue[0]>=10)lcd_yue[0]=0;
       lcd_pos(gb);
       lcd_wdat(lcd_yue[0]+0x30);
       lcd_pos(gb);
      }
      if(gb==0x0e)
      {
       lcd_ri[1]++;
       if(lcd_ri[1]>=4)lcd_ri[1]=0;
       lcd_pos(gb);
       lcd_wdat(lcd_ri[1]+0x30);
       lcd_pos(gb);
      }
      if(gb==0x0f)
      {
       lcd_ri[0]++;
       if(lcd_ri[0]>=10)lcd_ri[0]=0;
       lcd_pos(gb);
       lcd_wdat(lcd_ri[0]+0x30);
       lcd_pos(gb);
      }
      if(gb==0x45)
      {
       lcd_zhou[0]++;
       if(lcd_zhou[0]>=8)lcd_zhou[0]=0;
       lcd_pos(gb);
//       lcd_wdat(lcd_zhou[0]+0x30);
       dis_zhou(lcd_zhou[0]);
       lcd_pos(gb);
      }
      if(gb==0x47)
      {
       lcd_shi[1]++;
       if(lcd_shi[1]>=3)lcd_shi[1]=0;
       lcd_pos(gb);
       lcd_wdat(lcd_shi[1]+0x30);
       lcd_pos(gb);
      }
      if(gb==0x48)
      {
       lcd_shi[0]++;
       if(lcd_shi[0]>=10)lcd_shi[0]=0;
       lcd_pos(gb);
       lcd_wdat(lcd_shi[0]+0x30);
       lcd_pos(gb);
      }
      if(gb==0x4a)
      {
       lcd_fen[1]++;
       if(lcd_fen[1]>=6)lcd_fen[1]=0;
       lcd_pos(gb);
       lcd_wdat(lcd_fen[1]+0x30);
       lcd_pos(gb);
      }
      if(gb==0x4b)
      {
       lcd_fen[0]++;
       if(lcd_fen[0]>=10)lcd_fen[0]=0;
       lcd_pos(gb);
       lcd_wdat(lcd_fen[0]+0x30);
       lcd_pos(gb);
      }
      if(gb==0x4d)
      {
       lcd_miao[1]++;
       if(lcd_miao[1]>=6)lcd_miao[1]=0;
       lcd_pos(gb);
       lcd_wdat(lcd_miao[1]+0x30);
       lcd_pos(gb);
      }
      if(gb==0x4e)
      {
       lcd_miao[0]++;
       if(lcd_miao[0]>=10)lcd_miao[0]=0;
       lcd_pos(gb);
       lcd_wdat(lcd_miao[0]+0x30);
       lcd_pos(gb);
      }
     }
    }
   }
  }
 }
}
//***********************************************
/********************************************************************
* 名称 : Play_Song()
* 功能 : 播放蜂鸣器控制程序
* 输入 : i (选择播放哪首歌曲,0为“祝你平安”,1为“路边的野花你不要采”
* 输出 : 无
***********************************************************************/
void Play_Song(uchar i)
{
 uchar Temp1,Temp2;
 uint Addr; 
 Speak = 0;
 Count = 0;      //中断计数器清0
 Addr = i * 217;
 while(1)
 {
  Temp1 = SONG[Addr++];
     if (Temp1 == 0xFF)          //休止符
     {
      TR0 = 0;
      Delay_xMs(100);
     }
     else if (Temp1 == 0x00)   //歌曲结束符
     {
      return;
     }
     else
     {
      TR0 = 1;
   Temp2=SONG[Addr++];
     while(1)
     {
    Speak = ~Speak;
       Delay_xMs(Temp1);
       if(Temp2 == Count)
       {
        Count = 0;
        break;
       }
      }
     } 
  if(k==0)
  {
   delay1(10);
   if(k==0)
   {
    while(k==0);
    TR0=0;
    flag_c=0;
    Speak =0;
    delay1(10);
    return;
    
   }
  }
  dslcd();  
//  keyscan();
 }
}
//*******************************************************************
//*******************************************************************
void main()
{
 UartInit();
 Time0_Init();
 lcd_sta();
 Speak = 0;
 delay1(10);
 while(1)
 {
  dslcd();  
  keyscan();
  if((lcd_shi[1]==cshi[1])&&(lcd_shi[0]==cshi[0]))
  {
   if((lcd_fen[1]==cfen[1])&&(lcd_fen[0]==cfen[0]))
   {
    if(flag_c==1)
    {
     Play_Song(0);
    }
   }
  }
 }
}

 




关键词: 补交     进程     uchar     unsigned     数据     a    

共1条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]