|
新手一米,學(xué)習(xí)1628使用,分享1628固定地址寫數(shù)據(jù)。不喜勿噴。
單片機源程序如下:- #include "tm1628.h"
- sbit CLK = P0^6;
- sbit DIO = P0^5;
- sbit STB = P0^4;
- char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
- 0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
- /*管腳初始*/
- void gpio_config()
- {
- P0OE = (P0OE &~ 0X70) | 0X70;
- P0_4 = 1;
- P0_5 = 1;
- P0_6 = 1;
- }
- /*延時**/
- void delay_nop(unsigned char i)
- {
- unsigned char x;
- for(x=0;x<i;x++)
- {
- _nop_();_nop_();
- }
- }
- /*寫數(shù)據(jù)*/
- void tm1628_writeonebyte(unsigned char command)
- {
- unsigned char i;
- for(i=8;i>0;i--)
- {
- if( (command&0x01))
- {
- DIO = 1;
- }else
- {
- DIO = 0;
- }
- CLK = 0;
- delay_nop(10);
- command= command >>1;
- CLK = 1;
- }
- delay_nop(40);
- }
- /*寫命令*/
- void tm1628_wrcom(unsigned char com)
- {
- STB = 1;
- delay_nop(5);
- STB = 0;
- delay_nop(2);
- tm1628_writeonebyte(com);
- delay_nop(2);
- }
- /*寫地址,table數(shù)值*/
- void tm1628_adderdat(unsigned char add,unsigned char dat)
- {
- STB = 1;
- delay_nop(5);
- STB = 0;
- delay_nop(2);
- tm1628_writeonebyte(add);
- tm1628_writeonebyte(table[dat]);
- delay_nop(2);
- }
- /*指定地址,顯示數(shù)*/
- void tm1628_display(unsigned char adder,unsigned char val)
- {
- tm1628_wrcom(0x03); // 4位13段
- tm1628_wrcom(0x44); // 固定地址
-
- tm1628_adderdat(adder,val);
- tm1628_wrcom(0x8f); //開顯示
- STB = 1;
- delay_nop(100);
- }
復(fù)制代碼
|
-
-
1628.zip
2020-11-20 15:33 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
55.27 KB, 下載次數(shù): 122, 下載積分: 黑幣 -5
|