#include <reg52.h>
#define uchar unsigned char #define uint unsigned int #define CH452_SYSON1 0x0401 //#define CH452_SYSON1 0x0409 #define CH452_BCD 0x0580 //#define CH452_BCD 0x0500
#define CH452_RESET 0x0201 #define CH452_DIG0 0x0800 #define CH452_DIG1 0x0900 #define CH452_DIG2 0x0a00 #define CH452_DIG3 0x0b00 #define CH452_DIG4 0x0c00 #define CH452_DIG5 0x0d00 #define CH452_DIG6 0x0e00 #define CH452_DIG7 0x0f00
sbit CH452_DCLK = P1^2; sbit CH452_DIN = P1^3; sbit CH452_LOAD = P1^5; #define CH452_DCLK_SET {CH452_DCLK=1;} #define CH452_DCLK_CLR {CH452_DCLK=0;}
#define CH452_DIN_SET {CH452_DIN=1;} #define CH452_DIN_CLR {CH452_DIN=0;}
#define CH452_LOAD_SET {CH452_LOAD=1;} #define CH452_LOAD_CLR {CH452_LOAD=0;} void delay_2us(uchar con) { for(;con!=0;con--); }
void delay_30ms(void) { uchar dms1; uchar dms2; for(dms1=119;dms1!=0;dms1--) { for(dms2=15;dms2!=0;dms2--) delay_2us(1); } }
void CH452_Write(uint cmd) { uchar i; CH452_LOAD_CLR; CH452_DCLK_CLR; for(i=12;i!=0;i--) { CH452_DIN=cmd&1; CH452_DCLK_SET; cmd=cmd>>1; CH452_DCLK_CLR; } CH452_LOAD_SET; delay_2us(3); } void main() { //初始化 CH452_Write(CH452_RESET); delay_30ms(); //延迟30ms CH452_Write(CH452_SYSON1); //开启显示 while (1) { //"|"后面为显示内容,具体参考DATASHEET CH452_Write(CH452_DIG7 | 0x01); CH452_Write(CH452_DIG6 | 0x02); CH452_Write(CH452_DIG5 | 0x03); CH452_Write(CH452_DIG4 | 0x04); CH452_Write(CH452_DIG3 | 0x01); CH452_Write(CH452_DIG2 | 0x02); CH452_Write(CH452_DIG1 | 0x03); CH452_Write(CH452_DIG0 | 0x04); } }
//去官网下了个驱动,感觉太多了,自己搞了个比较少的,写得不是很好! //不过还好用哈!
//唯一的问题是,空白处有淡淡的重影,有谁知道怎么回事呀,难道是片子的病. 相关链接:https://bbs.21ic.com/upfiles/img/200710/2007107155839645.pdf |