1、ch452程序代码 2Ch452程序代码/*/* FileName: ch452.h */* Function: */*-History-*/* Author | Date | Status | Description */* wang | 2011/8/04 | create | */* | | | */*/#ifndef _CH452_H#define _CH452_H/#ifndef _CH452A_H_/#define _CH452A_H_/* Define command */#define CMD_SYSPARA 0x68/definiton for system paramete
2、r command default:0#define DISP 0x01 /0:disable 1:enable#define KEYB 0x02 /0:disable 1:enable#define WDOG 0x04 /0:close 1:open#define DPLR 0x08 /0:low level 1:high level#define SSPD 0x10 /0:low speed 1:high speed#define INTM 0x20 /0:low level 1:low level pulse#define GPOE 0x40 /0:all DIG as driver 1
3、:DIG6 DIG7 as GPIO#define CMD_DISPARA 0x6A/definiton for display parameter command default:0#define MODE 0x80 /0:No decode 1:BCD decode/#define LIMIT 0x70 /bit6bit4 range from 000 to 111#define INTENSITY 0x0F /bit3bit0 range from 0000 to 1111#define CMD_DISPDAT 0x70/加载字数据前八位#define CMD_GETKEY 0x6E/键
4、盘前八位#define CMD_ACKEN 0x6E/2线接口应答前八位/* Function prototype */void ch452a_two_ack(void);void ch452a_Init (void);void ch452a_sendcmd(unsigned char cmd,unsigned char paradata);/写命令unsigned char ch452a_getkey(void);/读取按键unsigned char CH452_ReadKeyboard();#define KEY_UP 0x59#define KEY_DOWN 0x58#define KE
5、Y_LEFT 0x5B#define KEY_RIGHT 0x5A#define KEY_SET 0x48#define KEY_OK 0x40#endif主程序代码:/* FileName: ch452.c * Function: *-History-* Author | Date | Status | Description * wang | 2011/7/28 | create | * | | | */#include STC_NEW_8051.h#include IIC.h#include Ch452.hsbit SCL=P10;sbit SDA=P11;/ FileName:ch45
6、2a_two_ack() / Function:Init_ack /void ch452a_two_ack() unsigned char i,wr_data; wr_data=CMD_ACKEN&0xfe; IIC_start();/* start condition */ for(i=0;i8;i+) if(wr_data&0x80)/判断高位数据 SDA=1; else SDA=0; wr_data=1;/让高位数据往左移 delays(1); SCL=1;/数据的写要在时钟为高电平时 delays(4); SCL=0; delays(5); /* nine clock */ SCL=0
7、; delays(1); SDA=1; delays(4); SCL=1; delays(5);/* send data */ for(i=0;i8;i+) SCL = 0; delays(1); SDA = 0; delays(4); SCL = 1; delays(5); IIC_stop(); / FileName:ch452a_Init() / Function:Init /void ch452a_Init(void) unsigned char cmddata,cmdadr; ch452a_two_ack(); cmddata=CMD_SYSPARA;/系统参数地址 cmdadr=D
8、ISP| KEYB & (INTM) & (DPLR);/系统参数数据 IIC_writedata(cmddata,&cmdadr,1); cmddata=CMD_DISPARA;/显示参数地址 cmdadr=MODE; IIC_writedata(cmddata,&cmdadr,1); / FunctionName: ch452a_sendcmd()/ Description: send command to ch452a /void ch452a_sendcmd (unsigned char cmd,unsigned char paradata) unsigned char cmddata
9、,cmdadr; cmddata = cmd; cmdadr = paradata; IIC_writedata(cmddata,&cmdadr,1); / FunctionName: ch452a_getkey()/ Description: get key value from ch452a /unsigned char ch452a_getkey() unsigned char cmddata,keycode;/ unsigned char* pData=&revdata; cmddata = CMD_GETKEY | 0x01; keycode=IIC_readdata(cmddata
10、); return keycode;/*unsigned char CH452_ReadKeyboard() unsigned char recvdata,cmddata; unsigned char ack; / uchar* pRecvData = &recvdata; cmddata = CMD_GETKEY | 0x01; IIC_start(); /启动 IIC_send(cmddata); /发送从机地址 ack=IIC_re_ack(ack); if(ack=0) recvdata = IIC_accept(cmddata); IIC_wr_ack(0); /主机发送应答给从机 IIC_stop(); else IIC_stop(); /ack条件不满足终止发送数据 return recvdata;*/*void ch452_flash(unsigned char cmd,unsigned char paradata) unsigned char cmddata,cmdadr; cmddata =0x; cmdadr = paradata; IIC_writedata(cmddata,&cmdadr,1); */
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1