/* MAIN.C file * * Copyright (c) 2002-2005 STMicroelectronics */ #include
// - - 定义函数 #define BIAS 0x52 //0b1000 0101 0010 1/3duty 4com #define SYSDIS 0X00 //0b1000 0000 0000 关振系统荡器和LCD偏压发生器 #define SYSEN 0X02 //0b1000 0000 0010 打开系统振荡器 #define LCDOFF 0X04 //0b1000 0000 0100 关LCD偏压 #define LCDON 0X06 //0b1000 0000 0110 打开LCD偏压 #define XTAL 0x28 //0b1000 0010 1000 外部接时钟 #define RC256 0X30 //0b1000 0011 0000 内部时钟 #define TONEON 0X12 //0b1000 0001 0010 打开声音输出 #define TONEOFF 0X10 //0b1000 0001 0000 关闭声音输出 #define WDTDIS 0X0A //0b1000 0000 1010 禁止看门狗 #define WDTDIS 0X0A unsigned int b,v,v1,i,miao,fen,shi,e,f,yu; unsigned char m,n,m1,n1,miaodian; unsigned int flag,year,month,day,hour,min,a,keytime,set; unsigned char Ht1621wTab[]={0x0b,0x00,0x07,0x05,0x0c,0x0d,0x0f,0x00,0x0f,0x0d}; //seg 16 unsigned char Ht1621cTab[]={0x0f,0x07,0x0d,0x0f,0x07,0x0b,0x0b,0x0f,0x0f,0x0f}; //seg 17 unsigned char Ht1621dTab[]={0x0e,0x06,0x0c,0x0e,0x06,0x0a,0x0a,0x0e,0x0e,0x0e}; //seg 17 unsigned char Ht1621eTab[]={0x00,0x0a,0x0d,0x0e}; _Bool CS @PC_ODR:5; _Bool WR @PC_ODR:6; _Bool DAT @PC_ODR:7; _Bool SCLK @PD_ODR:4; _Bool SDA @PD_ODR:5; _Bool RST @PD_ODR:6; _Bool k1 @PB_IDR:4; _Bool k2 @PC_IDR:3; _Bool k3 @PC_IDR:4; //HT1621控制位(液晶模块接口定义,根据自已的需要更改) #define CLS_HT_WR WR = 0 //拉低 #define SET_HT_WR WR = 1 //拉高 #define CLS_HT_CS CS = 0 //拉低 #define SET_HT_CS CS = 1 //拉高 #define SET_HT_DAT DAT= 1 //数据位 #define CLS_HT_DAT DAT = 0 //数据位 //GPIO口设置 void port_init(void) { PB_DDR |= 0x20; PB_CR1 |= 0x20; PB_CR2 |= 0x00; PD_DDR |= 0x74; PD_CR1 |= 0x04; PD_CR2 |= 0x00; PC_DDR |= 0xe0; PC_CR1 |= 0xe0; PC_CR2 |= 0x00; } void Init(void) { // CLK_ICKR |= 0x01; //打开内部高速RC //CLK_CKDIVR = 0x10; //HSI--4MHZ CLK_CKDIVR = 0x00; } //----------------------------------------------------------------------------------------- //函数名称:Delay() //功 能:延时子程序 //----------------------------------------------------------------------------------------- void Delay(char us) //5,7,9 { while(--us); } //----------------------------------------------------------------------------------------- //函数名称:DelayMS() //功 能:延时子程序 //----------------------------------------------------------------------------------------- void DelayMS(int iMs) { int i,j; for(i=0;i>=1; } } void write(unsigned char adress,unsigned char dat) { RST=0; SCLK=0; RST=1; Delay(20); writebyb(adress); writebyb(dat); SCLK=1; RST=0; } unsigned char readbybe(void) { unsigned i,dat; Delay(2); for(i=0;i<8;i++) { dat>>=1; if(SDA==1) { dat|=0x80; } else { dat&=0x7f; } SCLK=1; Delay(5); SCLK=0; Delay(5); } return dat; } unsigned char read(unsigned char adress) { unsigned char temp; RST=0; SCLK=0; RST=1; Delay(1); writebyb(adress); temp=readbybe(); SCLK=1; RST=0; SDA=0; return temp; } void ds1302(void) { write(0x8e,0x00); write(0x80,((0/10)<<4|(0%10))); //根据写秒寄存器命令字,写入秒的初始值 write(0x82,((0/10)<<4|(0%10))); //根据写分寄存器命令字,写入分的初始值 write(0x84,((12/10)<<4|(12%10))); //根据写小时寄存器命令字,写入小时的初始值 write(0x86,((16/10)<<4|(16%10))); //根据写日寄存器命令字,写入日的初始值 write(0x88,((11/10)<<4|(11%10))); //根据写月寄存器命令字,写入月的初始值 write(0x8c,((8/10)<<4|(8%10))); //根据写小时寄存器命令字,写入小时的初始值 write(0x8e,0x80); } void settime(void) { unsigned char ReadValue; ReadValue = read(0x81); //从秒寄存器读数据 miao=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F);//将读出数据转化 ReadValue = read(0x83); //从分寄存器读 min=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); //将读出数据转化 ReadValue = read(0x85); //从分寄存器读 hour=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); //将读出数据转化 ReadValue = read(0x87); //从分寄存器读 day=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); //将读出数据转化 ReadValue = read(0x89); //从分寄存器读 month=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); //将读出数据转化 ReadValue = read(0x8d); //从分寄存器读 year=((ReadValue&0x70)>>4)*10 + (ReadValue&0x0F); //将读出数据转化 } //----------------------------------------------------------------------------------------- //函数名称:Ht1621Wr_Data() //功 能:写数据函数,cnt为传送数据位数,数据传送为低位在前 //----------------------------------------------------------------------------------------- void Ht1621Wr_Data(char Data,char cnt) { char i; for (i=0;i
一般从网上下个驱动,改改就行,如果硬件没问题,就只要修改一下延时就行了,基本上属于体力活。。。