- #include
- #include"config.h"
- #include"1838.h"
- #include"1602.h"
- #include"dh11.h"
- #include"ds3231.h"
- #include"ta.h"
- //#include"adc.h"
- int main(void)
- {
- extern_12m();
- hc164_init();
- LCD_init();
- h1838_init();
- init_TA();
- // I2cByteWrite(0xD0,0x0e,0);
- // I2cByteWrite(0xD0,0x0f,0);
- // ModifyTime(15,7,19,12,07,00);//初始化时钟,2007/11/20,12/59/00
- //小时采用24小时制
- get_show_time();
- get_show_Temperature();
- dh11_read();
- // adc_init();
- _EINT();
- while (1)
- {
- // LCD_disp_string(0,0,"I AM A BOY?");
- // LCD_disp_string(0,1,"YOU ARE A GIRL!");
- Red_Code();
- Key_Icode(key_code[2]);
- }
- }
- #include"config.h"
- uchar change;
- void extern_12m()
- {
- WDTCTL = WDTPW + WDTHOLD; // Stop WDT
- if (CALBC1_12MHZ==0xFF) // If calibration constant erased
- {
- while(1); // do not load, trap CPU!!
- }
- DCOCTL = 0; // Select lowest DCOx and MODx settings
- BCSCTL1 = CALBC1_12MHZ;
- DCOCTL = CALDCO_12MHZ; // Load 8MHz constants
- }
- void hc164_init()
- {
- P1OUT &= ~(BIT6+BIT7+BIT3); // Clear P1.0
- P1DIR |=BIT6+BIT7+BIT3; // P1.0 output
- P2OUT &= ~(BIT0+BIT1+BIT2); // Clear P1.0
- P2DIR |=BIT0+BIT1+BIT2; // P1.0 output
- }
- void LCD_delay_10us(uint n) // - - 10微秒的延时子程序
- {
- uint i,j;
- for(i=n;i>0;i--)
- for(j=4;j>0;j--);
- }
- void sendbyte(uchar byte)
- {
- uchar c,num;
- num=byte;
- for(c=0;c<8;c++)
- {
- P1OUT&=~0x80;
- CLK0;
- P1OUT|=num&0x80; //(0x80即十进制的128, 二进制的10000000 按位发送
- CLK1;
- num<<=1;
- }
- }
- // - - 向LCD1602写指令
- void LCD_write_command(uchar dat)
- {
- LCD_delay_10us(2);
- LCD_RS_LOW; // - - 指令
- //LCD_RW_LOW; // - - 写入
- sendbyte(dat);
- LCD_delay_10us(2);
- LCD_EN_HIGH; // - - 允许
- LCD_delay_10us(2);
- LCD_EN_LOW;
- }
- // - - 向LCD1602写数据
- void LCD_write_data(uchar dat)
- {
- LCD_delay_10us(2);
- LCD_RS_HIGH;// - - 数据
- //LCD_RW_LOW;// - - 写入
- sendbyte(dat);
- LCD_delay_10us(2);
- LCD_EN_HIGH;// - - 允许
- LCD_delay_10us(2);
- LCD_EN_LOW;
- }
- // - - 设置显示位置
- void LCD_set_xy(uchar x,uchar y)
- {
- uchar address;
- if(y==1)
- {
- address=0x80+x; // - - 第一行位置
- } else {
- address=0xc0+x; // - - 第二行位置
- }
- // LCD_delay_10us(1);
- LCD_write_command(address);
- }
- // - - 显示一个字符函数
- void LCD_disp_char(uchar x,uchar y,uchar dat) // - - LCD_disp_char(0,1,0x38); // - - 显示8
- {
- LCD_set_xy(x,y);
- // LCD_delay_10us(1);
- LCD_write_data(dat);
- }
- // - - 显示一个字符串函数
- void LCD_disp_string(uchar x,uchar y,char *s)
- {
- LCD_set_xy(x,y);
- // LCD_delay_10us(1);
- while(*s!='\0')
- {
- LCD_write_data(*s);
- s++;
- }
- }
- void LCD_init(void)
- {
- LCD_delay_10us(20);
- LCD_write_command(0x38); // - - 设置8位格式,2行,5x7
- LCD_delay_10us(5);
- LCD_write_command(0x0c); // - - 整体显示,关光标,不闪烁
- LCD_delay_10us(5);
- LCD_write_command(0x06); // - - 设定输入方式,增量不移位
- LCD_delay_10us(5);
- LCD_write_command(0x01); // - - 清除屏幕显示
- LCD_delay_10us(200);
- }
- #include"config.h"
- #define IR_DIR_IN P2DIR&=~BIT3//红外接收头P1.0设置为输入,
- #define RED_R (P2IN&BIT3)//红外接收头输入值
- void h1838_init()
- {
- IR_DIR_IN;
- }
- uchar KEY_VAL;
- uchar key_code[4],code_value;
- void Red_Code()
- {
- uchar i,j,k = 0;
- for(i = 0;i < 19;i++)
- {
- delay_us(400); //延时400us
- if(RED_R) //9ms内有高电平,则判断为干扰,退出处理程序
- {
- return;
- }
- }
- while(!RED_R); //等待9ms低电平过去
- for(i=0;i<5;i++) //是否连发码
- {
- delay_us(500);
- if(!RED_R)
- {
- return;
- }
- }
- while(RED_R); //等待4.5ms高电平过去
- for(i = 0;i < 4;i++) //接收4个字节的数据
- {
- for(j = 0;j < 8;j++) //每个字节的数据8位
- {
- while(!RED_R); //等待变高电平
- while(RED_R) //计算高电平时间
- {
- delay_us(100);
- k++;
- if(k >22) //高电平时间过长,则退出处理程序
- {
- return;
- }
- }
- code_value>>=1; //接受一位数据
- if(k >= 7)
- {
- code_value|=0x80; //高电平时间大于0.56,则为数据1
- }
- k = 0; //计时清零
- }
- key_code=code_value; //四个字节的数据
- }
- // Key_Icode(); //调用赋值函数
- // Display_Key(KEY_VAL); //显示按键值
- // delay_ms(50);
- }
[color=rgb(51, 102, 153) !important]复制代码
- #include
- #define uchar unsigned char
- #define uint unsigned int
- #define ulong unsigned long
- #define CLK0 P1OUT&=~BIT6
- #define CLK1 P1OUT|=BIT6
- #define LCD_EN_HIGH P2OUT|=BIT2 //拉高
- #define LCD_EN_LOW P2OUT&=~BIT2 //拉低
- #define LCD_RW_HIGH P2OUT|=BIT1 //拉高
- #define LCD_RW_LOW P2OUT&=~BIT1 //拉低
- #define LCD_RS_HIGH P2OUT|=BIT0 //拉高
- #define LCD_RS_LOW P2OUT&=~BIT0 //拉低
- #define CPU_F ((double)12000000) //外部高频晶振8MHZ
- //#define CPU_F ((double)32768) //外部低频晶振32.768KHZ
- #define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
- #define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
- #define KEY_0 0x16 //键0
- #define KEY_1 0x0C //键1
- #define KEY_2 0x18 //键2
- #define KEY_3 0x5E //键3
- #define KEY_4 0x08 //键4
- #define KEY_5 0x1C //键5
- #define KEY_6 0x5A //键6
- #define KEY_7 0x42 //键7
- #define KEY_8 0x52 //键8
- #define KEY_9 0x4A //键9
- #define prex 0x44 //电源
- #define nex 0x40 //模式
- #define play_pause 0x43 //静音
- #define ch_ 0x45 //模式
- #define ch 0x46
- #define cha 0x47 //模式
- #define __ 0x07
- #define _a 0x15
- #define eq 0x09
- #define _100a 0x19
- #define _200a 0x0d
- #define power 0x12 //power
- #define up 0x1b //up
- #define down 0x1a //down
- #define left 0x04 //left
- #define right 0x06 //right
- #define ok 0x05 //0k
[color=rgb(51, 102, 153) !important]复制代码
- #include"config.h"
- //连接端口
- #define DHT11_Dir P1DIR
- #define DHT11_In P1IN
- #define DHT11_Out P1OUT
- #define DHT11_Bit BIT0
- char dh11_str[8];
- //8bit湿度+8bit湿度小数点
- //8bit温度+8bit温度小数点
- //数据位为0是高电平26~28us | 1高电平70us
- uchar DHT11_Data[5] = {0}; //从DHT11中读到的数据
- void read_DHT11(uchar *Data)
- {
- uchar re,m,n,Time_out;
- DHT11_Dir &= (~DHT11_Bit); //引脚为输入
- for(n = 0; n < 5; n++)
- {
- for(m = 0; m < 8; m++)
- {
- while( !(DHT11_In & DHT11_Bit) ); //每1bit以50us低电平时限开始,直到高电平到来
- delay_us(30);
- re = 0;
- if((DHT11_In & DHT11_Bit)) //30us后还是高电平说明是1
- {
- re = 1;
- }
- Time_out = 2;
- while((DHT11_In & DHT11_Bit) && (Time_out++ ));
- if(Time_out == 1) //超时处理
- {
- break;
- }
- *Data <<= 1;
- if(re)
- {
- *Data |= 0x01;
- }
- }
- Data++;
- }
- }
- //DHT11的握手协议模拟和数据的读取
- uchar DHT11_GetData(void)
- {
- uchar o,sum;
- DHT11_Dir |= DHT11_Bit;
- DHT11_Out &= ~DHT11_Bit; //拉低,发出开始信号
- delay_ms(18); //拉低18ms
- DHT11_Out |= DHT11_Bit; //拉高20us等待
- delay_us(20);
- DHT11_Dir &= (~DHT11_Bit);
- if( !(DHT11_In & DHT11_Bit) ) //DHT11响应
- {
- while( !(DHT11_In & DHT11_Bit) ); //80us低电平,等待DHT11的响应信号
- while( (DHT11_In & DHT11_Bit) ); //DHT11准备发送数据
- read_DHT11(DHT11_Data); //主机接收数据
- sum = 0;
- for(o = 0; o < 4; o++) //数据校验
- {
- sum += DHT11_Data[o];
- }
- if(sum != DHT11_Data[4])
- {
- return 0;
- }
- else
- {
- return 1;
- }
- }
- return 0;
- }
- //对温度湿度进行格式化(如果获取温度成功)
- void DHT11_format(char *Des_str)
- {
- Des_str[0] = DHT11_Data[0]/10 + 0x30;
- Des_str[1] = DHT11_Data[0]%10 + 0x30;
- Des_str[2] = '%';
- Des_str[3] = ' ';
- Des_str[4] = DHT11_Data[2]/10 + 0x30;
- Des_str[5] = DHT11_Data[2]%10 + 0x30;
- Des_str[6] = 'C';
- Des_str[7] = ' ';
- }
- void dh11_read()
- {
- if(DHT11_GetData())
- DHT11_format(dh11_str);
- LCD_disp_string(0,0,dh11_str);
- }
-
[color=rgb(51, 102, 153) !important]复制代码
- #include"config.h"
- #define SDA_DIR_OUT P1DIR|=BIT4
- #define SDA_DIR_IN P1DIR&=~BIT4
- #define SCL_DIR_OUT P1DIR|=BIT5
- #define SDA_IN P1IN&BIT4
- #define SDA1 P1OUT|=BIT4
- #define SDA0 P1OUT&=~BIT4
- #define SCL1 P1OUT|=BIT5
- #define SCL0 P1OUT&=~BIT5
- uchar year,month,date,hour,minute,second;
- uchar const table[]={'0','1','2','3','4','5','6','7','8','9'};
- uchar const month_12[]={31,29,31,30,31,30,31,31,30,31,30,31};
- uchar clockset,clockon,clockoff[5],clock_on;
- uchar oclock[5][2];
- uchar BCD2HEX(uchar val) //BCD转换为Byte
- {
- uchar temp;
- temp=val&0x0f;
- val>>=4;
- val&=0x0f;
- val*=10;
- temp+=val;
- return temp;
- }
- uchar HEX2BCD(uchar val) //B码转换为BCD码
- {
- uchar i,j,k;
- i=val/10;
- j=val%10;
- k=j+(i<<4);
- return k;
- }
- void Start_I2C()
- {
- SDA_DIR_OUT;
- SCL_DIR_OUT;
- SDA1; //发送起始条件的数据信号
- delay_us(5);
- SCL1;
- delay_us(5); //起始条件建立时间大于4.7us,延时
- SDA0; //发送起始信号
- delay_us(5); // 起始条件锁定时间大于4μs
- // SCL0; //钳住I2C总线,准备发送或接收数据
- // delay_us(2);
- }
- void Stop_I2C()
- {
- SDA_DIR_OUT;
- SCL_DIR_OUT;
- SDA0; //发送结束条件的数据信号
- delay_us(5); //发送结束条件的时钟信号
- SCL1; //结束条件建立时间大于4us
- delay_us(5);
- SDA1; //发送I2C总线结束信号
- delay_us(1);
- }
- void SendByte(uchar c)
- {
- uchar BitCnt;
- SDA_DIR_OUT;
- SCL_DIR_OUT;
- SCL0;
- delay_us(10);
- for(BitCnt=0;BitCnt<8;BitCnt++) //要传送的数据长度为8位
- {
- if(c&0x80)
- SDA1; //判断发送位
- else
- SDA0;
- delay_us(1);
- SCL0; //置时钟线为高,通知被控器开始接收数据位
- delay_us(1); //保证时钟高电平周期大于4μs
- SCL1;
- delay_us(5);
- c=c<<1;
- SCL0; //置时钟线为高,通知被控器开始接收数据位
- delay_us(5);
- }
- SDA1; //8位发送完后释放数据线,准备接收应答位
- delay_us(1);
- SCL0;
- delay_us(1);
- SCL1;
- delay_us(1);
- SCL0;
- }
- uchar ReceiveByte(uchar b)
- {
- uchar i;
- uchar temp;
- uchar Dat=0;
- /*
- SDA_H;
- delay(5);
- SCL_L;
- delay(5);
- */
- SDA_DIR_IN;
- for(i=0;i<8;i++)
- {
- SCL1;
- delay_us(5);
- Dat=Dat<<1;
- delay_us(1);
- temp=SDA_IN;
- if(temp&0x10)
- Dat|=0x01;
- else
- Dat|=0x00;
- delay_us(1);
- SCL0;
- delay_us(5);
- }
- SDA_DIR_OUT;
- if(b)//每收一个数后发送ACK或nACK
- SDA1;
- else
- SDA0;
- delay_us(1);
- SCL1;
- delay_us(1);
- SCL0;
- delay_us(1);
- SDA1; //释放总线
- delay_us(1);
- return Dat;
- }
- /****************************************************/
- /***********将一个字节写入DS3231指定的地址***********/
- void I2cByteWrite(uchar device,uint addr,uchar bytedata)
- {
- Start_I2C();
- // delay_us(1);
- SendByte(device);
- // delay_us(1);
- SendByte(addr);
- // delay_us(1);
- SendByte(bytedata);
- // delay_us(1);
- Stop_I2C();
- }
- /****************************************************/
- /************从DS3231指定的地址读一个字节************/
- uchar I2cByteRead(uchar device,uint addr)
- {
- uchar Dat=0;
- Start_I2C();
- SendByte(device);
- // delay_us(1);
- SendByte(addr);
- // delay_us(1);
- Start_I2C();
- SendByte(0xd1);//读数
- // delay_us(1);
- Dat=ReceiveByte(1);//只接收一个字节,所以发nACK
- Stop_I2C();
- return Dat;
- }
- /***************************************************/
- /*********************读取时间**********************/
- void Readtime(void)
- {
- year=I2cByteRead(0xd0,0x06); //年
- month=I2cByteRead(0xd0,0x05); //月
- date=I2cByteRead(0xd0,0x04); //日
- hour=I2cByteRead(0xd0,0x02); //时
- minute=I2cByteRead(0xd0,0x01);//分
- second=I2cByteRead(0xd0,0x00);//秒
- }
- /***************************************************/
- /****************修改时间,BCD码输入*****************/
- void ModifyTime(uchar yea,uchar mon,uchar da,uchar hou,uchar min,uchar sec)
- {
- uchar temp=0;
- temp=HEX2BCD(yea);
- I2cByteWrite(0xD0,0x06,temp);//修改年
- temp=HEX2BCD(mon);
- I2cByteWrite(0xD0,0x05,temp);//修改月
- temp=HEX2BCD(da);
- I2cByteWrite(0xD0,0x04,temp);//修改日
- temp=HEX2BCD(hou);
- I2cByteWrite(0xD0,0x02,temp);//修改时
- temp=HEX2BCD(min);
- I2cByteWrite(0xD0,0x01,temp);//修改分
- temp=HEX2BCD(sec);
- I2cByteWrite(0xD0,0x00,temp);//修改秒
- }
- /****************************************************/
- /****************读取时间 计算 并显示****************/
- void get_show_time(void)
- {
- uchar temp1,temp2;
- char a[2];
- temp1=I2cByteRead(0xd0,0x06); //年
- temp2=BCD2HEX(temp1);
- a[0]=table[temp2/10];
- a[1]=table[temp2%10];
- LCD_disp_string(0,1,a);
- LCD_disp_char(2,1,'-');
- temp1=I2cByteRead(0xd0,0x05); //月
- temp2=BCD2HEX(temp1);
- a[0]=table[temp2/10];
- a[1]=table[temp2%10];
- LCD_disp_string(3,1,a);
- LCD_disp_char(5,1,'-');
- temp1=I2cByteRead(0xd0,0x04); //日
- temp2=BCD2HEX(temp1);
- a[0]=table[temp2/10];
- a[1]=table[temp2%10];
- LCD_disp_string(6,1,a);
- LCD_disp_char(8,1,'-');
- temp1=I2cByteRead(0xd0,0x03); //星期
- temp2=BCD2HEX(temp1);
- temp2=table[temp2];
- LCD_disp_char(9,1,temp2);
- LCD_disp_char(10,1,' ');
- LCD_disp_char(8,0,' ');
- if(clockset==0)
- {
- temp1=I2cByteRead(0xd0,0x02); //时 24小时制
- temp1&=0x3f;
- temp2=BCD2HEX(temp1);
- a[0]=table[temp2/10];
- a[1]=table[temp2%10];
- LCD_disp_string(8,0,a);
- LCD_disp_char(10,0,':');
- temp1=I2cByteRead(0xd0,0x01); //分
- temp2=BCD2HEX(temp1);
- a[0]=table[temp2/10];
- a[1]=table[temp2%10];
- LCD_disp_string(11,0,a);
- LCD_disp_char(13,0,':');
- temp1=I2cByteRead(0xd0,0x00); //秒
- temp2=BCD2HEX(temp1);
- a[0]=table[temp2/10];
- a[1]=table[temp2%10];
- LCD_disp_string(14,0,a);
- }
- if(clockset!=0)
- {
- LCD_disp_string(8,0," ");
- a[0]=table[oclock[clockset-1][0]/10];
- a[1]=table[oclock[clockset-1][0]%10];
- LCD_disp_string(8,0,a);
- LCD_disp_char(10,0,'-');
- a[0]=table[oclock[clockset-1][1]/10];
- a[1]=table[oclock[clockset-1][1]%10];
- LCD_disp_string(11,0,a);
- LCD_disp_string(13,0,"CK");
- LCD_disp_char(15,0,table[clockoff[clockset-1]]);
- }
- }
- //显示温度
- void get_show_Temperature(void)
- {
- if(change==0)
- {
- uchar Ttemp1,Ttemp2;
- char a[2];
- Ttemp1=I2cByteRead(0xd0,0x11); //温度 高字节
- Ttemp2=BCD2HEX(Ttemp1);
- // LCD_disp_string(9,1," ");
- // Ttemp3=I2cByteRead(0xd0,0x12); //温度低字节
- // Ttemp4=BCD2HEX(Ttemp3);
- a[0]=table[Ttemp2/10];
- a[1]=table[Ttemp2%10];
- LCD_disp_string(13,1,a);
- LCD_disp_char(15,1,'c');
- }
- if(change!=0)
- {
- LCD_disp_string(13,1," ");
- LCD_disp_char(15,1,table[change-1]);
- }
- if((clockset!=0)&&(change==0))
- {
- LCD_disp_string(13,1," ");
- LCD_disp_char(13,1,table[clockset]);
- LCD_disp_char(15,1,table[clockon]);
- }
- }
- void change_del()
- {
- uchar temp1,temp2,temp3,temp4;
- if(change>0)
- {
- temp1=I2cByteRead(0xd0,change-1);
- temp2=BCD2HEX(temp1);
- temp2-=1;
- if(change<3)
- {
- if(temp2>59)
- temp2=59;
- }
- if(change==3)
- {
- if(temp2>23)
- temp2=23;
- }
- if(change==4)
- {
- if(temp2==0)
- temp2=7;
- }
- if(change==5)
- {
- if(temp2==0)
- {
- temp3=I2cByteRead(0xd0,0x05);
- temp4=BCD2HEX(temp3);
- temp2=month_12[temp4-1];
- }
- }
- if(change==6)
- {
- if(temp2==0)
- temp2=12;
- }
- temp2=HEX2BCD(temp2);
- I2cByteWrite(0xD0,change-1,temp2);//修改年
- }
- }
- void change_add()
- {
- uchar temp1,temp2,temp3,temp4;
- if(change>0)
- {
- temp1=I2cByteRead(0xd0,change-1);
- temp2=BCD2HEX(temp1);
- temp2+=1;
- if(change<3)
- {
- if(temp2>59)
- temp2=0;
- }
- if(change==3)
- {
- if(temp2>23)
- temp2=0;
- }
- if(change==4)
- {
- if(temp2==8)
- temp2=1;
- }
- if(change==5)
- {
- temp3=I2cByteRead(0xd0,0x05);
- temp4=BCD2HEX(temp3);
- if(temp2>month_12[temp4-1])
- temp2=1;
- }
- if(change==6)
- {
- if(temp2==13)
- temp2=1;
- }
- temp2=HEX2BCD(temp2);
- I2cByteWrite(0xD0,change-1,temp2);//修改年
- }
- }
- void change_set()
- {
- ++change;
- if(change>=8)
- change=0;
- }
- void clock_set()
- {
- ++clockset;
- if(clockset>=6)
- clockset=0;
- }
- void clock_add()
- {
- change=0;
- ++clockon;
- if( clockon==3)
- clockon=0;
- }
- void clock_change()
- {
- if(clockon==1)
- {
- ++oclock[clockset-1][1];
- if(oclock[clockset-1][1]>59)
- oclock[clockset-1][1]=0;
- }
- if(clockon==2)
- {
- ++oclock[clockset-1][0];
- if(oclock[clockset-1][0]>23)
- oclock[clockset-1][0]=0;
- }
- }
- void Key_Icode(uchar dat)
- {
- LCD_disp_char(10,1,' ');
- // LCD_disp_string(10,1," ");
- switch(dat) //第3个字节是数据,第4个字节是反码
- { //为了更稳定,可以加上第4个字节数据的判断
- case KEY_0:KEY_VAL=0; LCD_disp_char(11,1,KEY_VAL+0x30); LCD_disp_char(12,1,' '); break;
- case KEY_1:KEY_VAL=1; LCD_disp_char(11,1,KEY_VAL+0x30); LCD_disp_char(12,1,' '); break;
- case KEY_2:KEY_VAL=2; LCD_disp_char(11,1,KEY_VAL+0x30); LCD_disp_char(12,1,' '); break;
- case KEY_3:KEY_VAL=3; LCD_disp_char(11,1,KEY_VAL+0x30); LCD_disp_char(12,1,' ');break;
- case KEY_4:KEY_VAL=4; LCD_disp_char(11,1,KEY_VAL+0x30); LCD_disp_char(12,1,' ');break;
- case KEY_5:KEY_VAL=5; LCD_disp_char(11,1,KEY_VAL+0x30); LCD_disp_char(12,1,' ');break;
- case KEY_6:KEY_VAL=6; LCD_disp_char(11,1,KEY_VAL+0x30); LCD_disp_char(12,1,' ');break;
- case KEY_7:KEY_VAL=7; LCD_disp_char(11,1,KEY_VAL+0x30); LCD_disp_char(12,1,' ');break;
- case KEY_8:KEY_VAL=8; LCD_disp_char(11,1,KEY_VAL+0x30); LCD_disp_char(12,1,' ');break;
- case KEY_9:KEY_VAL=9; LCD_disp_char(11,1,KEY_VAL+0x30); LCD_disp_char(12,1,' ');break;
- case prex:LCD_disp_string(11,1,"PR");clock_change();break;
- case nex :LCD_disp_string(11,1,"NX");clock_add();break;
- case play_pause:LCD_disp_string(11,1,"PS");clock_set();break;
- case ch_: LCD_disp_string(11,1,"C-");change_del();break;
- case ch: LCD_disp_string(11,1,"CH");change_set();break;
- case cha:LCD_disp_string(11,1,"C+");change_add();break;
- case eq: LCD_disp_string(11,1,"EQ");
- if(clockoff[clockset-1]==0)
- clockoff[clockset-1]=1;
- else clockoff[clockset-1]=0;
- break;
- case _a:LCD_disp_string(11,1,"V+");break;
- case __:LCD_disp_string(11,1,"V-");break;
- case _100a:LCD_disp_string(11,1,"1+");break;
- case _200a:LCD_disp_string(11,1,"2+");break;
- case power:LCD_disp_string(11,1,"PW");break;
- case up: LCD_disp_string(11,1,"UP");break;
- case down:LCD_disp_string(11,1,"DW");break;
- case left:LCD_disp_string(11,1,"LF");break;
- case right:LCD_disp_string(11,1,"RT");break;
- case ok:LCD_disp_string(11,1,"OK");break;
- default:KEY_VAL=' ';break;
- }
- key_code[2]=' ';
- }
- void oclockon()
- {
- uchar clock_flag[5];
- uchar temp1,temp2,temp3;
- temp1=I2cByteRead(0xd0,0x02); //时 24小时制
- temp1&=0x3f;
- temp2=BCD2HEX(temp1);
- temp1=I2cByteRead(0xd0,0x01); //分
- temp3=BCD2HEX(temp1);
- uchar i;
- for(i=0;i<5;i++)
- {
- if(temp2==oclock[0])
- {
- if(temp3==oclock[1])
- {
- if(clockoff==1)
- clock_flag=1;
- else clock_flag=0;
- }
- else clock_flag=0;
- }
- else clock_flag=0;
- }
- clock_on=0;
- for(i=0;i<5;i++)
- {
- if(clock_flag==1)
- clock_on=1;
- }
- }
-
[color=rgb(51, 102, 153) !important]复制代码
- #include"config.h"
- uchar t;
- /***********TA初始化*********/
- void init_TA()
- {
- TACCTL0 = CCIE; // TACCR0 interrupt enabled
- TACCR0 = 60000; //5ms中断一次
- TACTL = TASSEL_2 + MC_1; // SMCLK, upmode
- }
- #pragma vector=TIMER0_A0_VECTOR
- __interrupt void Timer_A (void)
- {
- if(++t==200)
- {
- t=0;
- dh11_read();
- get_show_Temperature();
- get_show_time();
- oclockon();
- }
- if(clock_on==1)
- P1OUT ^= 0x08;
- }
本帖最后由 Jacktang 于 2015-9-27 11:19 编辑
暂无评论,赶紧抢沙发吧