#include <reg51.h>
// By Paprika
// 主要目的是實(shí)現(xiàn)對ch452的基本寫操作,理解時序過程
sbit ch451_din = P2^6; // 串行數(shù)據(jù)輸出,接CH451的數(shù)據(jù)輸入
sbit ch451_load=P3^3; //串行命令加載,上升延激活
sbit ch451_dout=P2^7; //INT1,鍵盤中斷和鍵值數(shù)據(jù)輸入,接CH451的數(shù)據(jù)輸出
sbit ch451_dclk = P2^5; //串行數(shù)據(jù)時鐘上升延激活
//數(shù)字參數(shù);數(shù)碼管參數(shù)、板子連線、ch452數(shù)據(jù)手冊可得,其他字母需要自己計(jì)算
#define number1 0x18
#define number2 0xd5
#define number3 0xd9
#define number4 0x78
#define number5 0xe9
#define number6 0xed
#define number7 0x98
#define number8 0xfd
#define number9 0xf9
#define number0 0xbd
/* CH451和CH452的常用命令碼 */
#define CH452_NOP 0x0000 // 空操作
#define CH452_RESET 0x0201 // 復(fù)位
#define CH452_LEVEL 0x0100 // 加載光柱值,需另加7位數(shù)據(jù)
#define CH452_CLR_BIT 0x0180 // 段位清0,需另加6位數(shù)據(jù)
#define CH452_SET_BIT 0x01C0 // 段位置1,需另加6位數(shù)據(jù)
#define CH452_SLEEP 0x0202 // 進(jìn)入睡眠狀態(tài)
#define CH452_LEFTMOV 0x0300 // 設(shè)置移動方式-左移
#define CH452_LEFTCYC 0x0301 // 設(shè)置移動方式-左循環(huán)
#define CH452_RIGHTMOV 0x0302 // 設(shè)置移動方式-右移
#define CH452_RIGHTCYC 0x0303 // 設(shè)置移動方式-右循環(huán)
#define CH452_SELF_BCD 0x0380 // 自定義BCD碼,需另加7位數(shù)據(jù)
#define CH452_SYSOFF 0x0400 // 關(guān)閉顯示、關(guān)閉鍵盤
#define CH452_SYSON1 0x0401 // 開啟顯示
#define CH452_SYSON2 0x0403 // 開啟顯示、鍵盤
#define CH452_SYSON2W 0x0423 // 開啟顯示、鍵盤, 真正2線接口
#define CH452_NO_BCD 0x0500 // 設(shè)置默認(rèn)顯示方式,可另加3位掃描極限
#define CH452_BCD 0x0580 // 設(shè)置BCD譯碼方式,可另加3位掃描極限
#define CH452_TWINKLE 0x0600 // 設(shè)置閃爍控制,需另加8位數(shù)據(jù)
#define CH452_GET_KEY 0x0700 // 獲取按鍵,返回按鍵代碼
#define CH452_DIG0 0x0800 // 數(shù)碼管位0顯示,需另加8位數(shù)據(jù)
#define CH452_DIG1 0x0900 // 數(shù)碼管位1顯示,需另加8位數(shù)據(jù)
#define CH452_DIG2 0x0a00 // 數(shù)碼管位2顯示,需另加8位數(shù)據(jù)
#define CH452_DIG3 0x0b00 // 數(shù)碼管位3顯示,需另加8位數(shù)據(jù)
#define CH452_DIG4 0x0c00 // 數(shù)碼管位4顯示,需另加8位數(shù)據(jù)
#define CH452_DIG5 0x0d00 // 數(shù)碼管位5顯示,需另加8位數(shù)據(jù)
#define CH452_DIG6 0x0e00 // 數(shù)碼管位6顯示,需另加8位數(shù)據(jù)
#define CH452_DIG7 0x0f00 // 數(shù)碼管位7顯示,需另加8位數(shù)據(jù)
//延時程序
void delay(void){
char i,j,k;
for(i=0;i<10;i++);
}
// 寫程序
void ch451_write(unsigned int command)
{
char i;
ch451_load=0;
for(i=0;i<12;i++){ //送入12位數(shù)據(jù),低位在前
ch451_din = command&1;
ch451_dclk =0;
command>>=1;
ch451_dclk=1; //上升沿有效
delay();
}
ch451_load=1;
}
void main(){
ch451_write(CH452_SYSON1);
ch451_write(CH452_DIG4 | number5);
ch451_write(CH452_DIG5 | number5);
ch451_write(CH452_DIG6 | number5);
ch451_write(CH452_DIG7 | number5);
// ch451_write(CH452_DIG3 | 1);
//ch451_write(CH452_DIG2 | 1);
//ch451_write(CH452_DIG1 | 7);
// ch451_write(CH452_DIG0 | 8); // 顯示字符8