FD650b驱动
- #include "my_fd650b.h"
- #include"stc15f2k60s2.h"
- #include"dingshiqi.h"
- u8 key_fd650b_data = 0;
- sbit din = P3^0;
- sbit sclk = P3^1;
- sbit FD650b_SDA_READ = P3^0;
- #define FD650b_SCL_SET() {sclk = 1;}
- #define FD650b_SCL_CLR() {sclk = 0;}
- #define FD650b_SDA_SET() {din = 1;}
- #define FD650b_SDA_CLR() {din = 0;}
- /* the numbering of the frontpanel LED:
- --0--
- 5| |1
- --6--
- 4| |2
- --3-- .7
- */
- u8 code FD650b_SegCode[]= {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71}; //共阴段码
- void dela_xus(u8 i)
- {
- u8 j,k;
- for(k=0;k<i;k++)for(j=0;j<10;j++);
- }
- void FD650b_Start(void)
- {
- // FD650_SDA_D_OUT(); //SDA输出模式
- FD650b_SDA_SET();
- FD650b_SCL_SET();
- //FD650_DELAY();
- dela_xus(2);
- FD650b_SDA_CLR();
- //FD650_DELAY();
- dela_xus(2);
- FD650b_SCL_CLR();
- }
- void FD650b_Stop(void)
- {
- // FD650_SDA_D_OUT(); //SDA输出模式
- FD650b_SDA_CLR();
-
- dela_xus(2);
- FD650b_SCL_SET();
- dela_xus(2);
- FD650b_SDA_SET();
- dela_xus(2);
- // FD650_SDA_D_IN(); //SDA输入模式
- }
- void FD650b_WriteOneByte(u8 WriteByte)
- {
- u8 i;
- for(i = 0; i != 8; i++)
- {
- if(WriteByte & 0x80)
- {
- FD650b_SDA_SET();
- }
- else
- {
- FD650b_SDA_CLR();
- }
-
- dela_xus(2);
- FD650b_SCL_SET();
- WriteByte <<= 1;
-
- dela_xus(2);
- FD650b_SCL_CLR();
- }
- FD650b_SDA_SET();
- dela_xus(2);
- FD650b_SCL_SET();
- dela_xus(2);
- FD650b_SCL_CLR();
- }
- void FD650b_SDA_D_IN(){ //SDA输入模式
- FD650b_Start();
- FD650b_WriteOneByte(0x4f); //68H,6AH,6CH,6EH对应4个数码管
- }
- u8 FD650b_ReadOneByte(void)
- {
- u8 i, ReadByte = 0;
-
- FD650b_SDA_D_IN(); //SDA输入模式
- FD650b_SDA_SET();
- for(i = 0; i != 8; i++)
- {
- dela_xus(2);
- FD650b_SCL_SET();
- dela_xus(2);
- ReadByte <<= 1;
-
- if(FD650b_SDA_READ) ReadByte++;
- FD650b_SCL_CLR();
- }
- FD650b_SDA_SET();
- dela_xus(2);
- FD650b_SCL_SET();
- dela_xus(2);
- FD650b_SCL_CLR();
- return ReadByte;
- }
- void my_FD650_WriteCommand(u8 comm,u8 dat)
- {
- FD650b_Start();
- FD650b_WriteOneByte(comm); //68H,6AH,6CH,6EH对应4个数码管
- FD650b_WriteOneByte(dat);
- FD650b_Stop();
- }
- void my_FD650_Display(u8 Data1, u8 Data2, u8 Data3, u8 Data4, u8 Brightness)//FD650b_DispSegCode
- {
- my_FD650_WriteCommand(0x48 , 0x11);
- // my_FD650_WriteCommand(0x48 , Brightness);
- my_FD650_WriteCommand(0x68 , FD650b_SegCode[Data1]); //FD650_DIG0 = 0x1400
- my_FD650_WriteCommand(0x6a , FD650b_SegCode[Data2]); //FD650_DIG1 = 0x1500
- my_FD650_WriteCommand(0x6c , FD650b_SegCode[Data3]); //FD650_DIG2 = 0x1600
- my_FD650_WriteCommand(0x6e , FD650b_SegCode[Data4]); //FD650_DIG3 = 0x1700
- }
- /*
- 0x44-0x7f有效,不按下也有码输出,是之前码的,有按下时+0X40
- */
- void read_fd650key()
- {
- u8 key_fd650 ;
- key_fd650b_data = 0;
- key_fd650 = FD650b_ReadOneByte();
-
- switch(key_fd650){
- case 0x6f:
- key_fd650b_data = 1;
- break;
- case 0x47:
- key_fd650b_data = 2;
- break;
- case 0x5f:
- key_fd650b_data = 3;
- break;
- case 0x67:
- key_fd650b_data = 4;
- break;
- case 0x57:
- key_fd650b_data = 5;
- break;
- case 0x4f:
- key_fd650b_data = 6;
- break;
- default: break;
- }
- my_FD650_WriteCommand(0x48 , 0x11);
- // my_FD650_WriteCommand(0x48 , Brightness);
- my_FD650_WriteCommand(0x68 , FD650b_SegCode[key_fd650b_data ]); //FD650_DIG0 = 0x1400
- my_FD650_WriteCommand(0x6a , FD650b_SegCode[2]); //FD650_DIG1 = 0x1500
- my_FD650_WriteCommand(0x6c , FD650b_SegCode[key_fd650 >> 4]); //FD650_DIG2 = 0x1600
- my_FD650_WriteCommand(0x6e , FD650b_SegCode[key_fd650 & 0x0f]); //FD650_DIG3 = 0x1700
- }
复制代码
my_fd650b.h
- #ifndef __MY_FD650B_H
- #define __MY_FD650B_H
- #define u8 unsigned char
- #define u16 unsigned int
- #define u32 unsigned long
- void read_fd650key();
- void my_FD650_Display(u8 Data1, u8 Data2, u8 Data3, u8 Data4, u8 Brightness);//FD650b_DispSegCode
- #endif
复制代码
|