终于 终于看到有人咨询TM1650的问题了 那么我就不得不把我珍藏多年的1650库分享出来了
- #ifndef __STC32G_tm1650_H
- #define __STC32G_tm1650_H
-
- #include "config.h"
-
- #define tm1650_sda DIO
- #define tm1650_scl CLK
- #define smg1 0x68
- #define smg2 0x6a
- #define smg3 0x6c
- #define smg4 0x6e
-
- #define L_Du01 0x11
- #define L_Du02 0x21
- #define L_Du03 0x31
- #define L_Du04 0x41
- #define L_Du05 0x51
- #define L_Du06 0x61
- #define L_Du07 0x71
- #define L_Du08 0x81
-
-
- void tm1650_start();
- void tm1650_stop();
-
- void tm1650_write_1byte(unsigned char onebyte);
- void tm1650_ack();
-
-
- extern void tm1650_write_display(unsigned char ADD,unsigned char DATA);
- extern void tm1650_init();
- extern void tm1650_write(unsigned char DATA1,unsigned char DATA2,unsigned char DATA3,unsigned char DATA4);
-
- #endif
-
-
- 这部分是.H 文件
复制代码
- #include "STC32G_TM1650.h"
-
- extern u8 code tab[];
- extern u8 code tab_ud[];
- void tm1650_start()
- {
- tm1650_sda = 1;
- tm1650_scl = 1;
-
- tm1650_sda = 0;
-
- }
-
- void tm1650_stop()
- {
- tm1650_sda = 0;
- tm1650_scl = 1;
-
- tm1650_sda = 1;
-
- }
-
- void tm1650_ack(void)
- {
- unsigned char timeout = 0;
- tm1650_scl = 1;
-
- tm1650_scl = 0;
- do timeout++;
- while((tm1650_sda)&&(timeout<255));
-
- tm1650_scl = 0;
- }
-
- void tm1650_write_1byte(unsigned char onebyte)
- {
- unsigned char i;
-
- for (i=0;i<8;i++)
- {
- tm1650_scl = 0;
-
- if(onebyte & 0x80)
- {
- tm1650_sda = 1;
- }
- else
- {
- tm1650_sda = 0;
- }
- onebyte = onebyte<<1;
-
- tm1650_scl = 1;
-
- tm1650_scl = 0;
-
- }
- }
-
- void tm1650_write_display(unsigned char ADD,unsigned char DATA)
- {
- tm1650_start();
- tm1650_write_1byte(ADD);
- tm1650_ack();
- tm1650_write_1byte(DATA);
- tm1650_ack();
- tm1650_stop();
- }
-
- void tm1650_init()
- {
- tm1650_write_display(0x48,L_Du06);
- tm1650_write_display(smg1,tab[0]);
- tm1650_write_display(smg2,tab[1]);
- tm1650_write_display(smg3,tab[2]);
- tm1650_write_display(smg4,tab[3]);
- }
-
- void tm1650_write(unsigned char DATA1,unsigned char DATA2,unsigned char DATA3,unsigned char DATA4)
- {
- tm1650_write_display(0x48,L_Du03);
- tm1650_write_display(smg1,tab[DATA1]);
- tm1650_write_display(smg2,tab[DATA2]);
- tm1650_write_display(smg3,tab[DATA3]);
- tm1650_write_display(smg4,tab[DATA4]);
- }
-
- 这部分是.c文件
复制代码
- u8 code tab[21] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71,0X80,0X23,0X1C,0X40,0X00};
- u8 code tab_ud[5] = {0X00,0x23,0x54,0x62,0x1C};
- 这部分是mian文件中的字符数组
-
-
- void GPIO_config(void)
- {
- P1_MODE_IO_PU(GPIO_Pin_HIGH); //P1.4,P.5,P1.6,P.7 设置为准双向口
- P2_MODE_IO_PU(GPIO_Pin_4 | GPIO_Pin_5); //P2.4,P2.5 设置为准双向口
- P4_MODE_IO_PU(GPIO_Pin_6 | GPIO_Pin_7); //P4.6,P4.7 设置为准双向口
- P7_MODE_IO_PU(GPIO_Pin_HIGH);
- I2C_SW(I2C_P24_P25); //I2C_P14_P15,I2C_P24_P25,I2C_P76_P77,I2C_P33_P32
- UART2_SW(UART2_SW_P46_P47); //UART2_SW_P10_P11,UART2_SW_P46_P47
-
- // P_MODE_IO_PU(GPIO_Pin_HIGH); //P1.4,P.5,P1.6,P.7 设置为准双向口
-
-
- }
- 这部分是mian文件中的GPIO初始化设置
-
-
- void main(void)
- {
- u8 i,j;
- u8 addr;
- u8 status;
-
- WTST = 0; //设置程序指令延时参数,赋值为0可将CPU执行指令的速度设置为最快
- EAXSFR(); //扩展SFR(XFR)访问使能
- CKCON = 0; //提高访问XRAM速度
-
- GPIO_config();
- // I2C_config();
- DMA_config();
- UART_config();
- tm1650_init();
- EA = 1;
- printf("命令设置:\r\n");
- printf("W 0x12 1234567890 --> 写入操作 十六进制地址 写入内容\r\n");
- printf("R 0x12 10 --> 读出操作 十六进制地址 读出字节内容\r\n");
- 这部分是mian函数中的初始化程序
-
-
-
- sbit CLK = P7^6;
- sbit DIO = P7^5;
- 这是config文件中端口设置
-
-
- 实际使用中只需要吧端口设置这里改成自己需要的 然后初始化那里改一下端口就行了
复制代码
|