TM1616程序源代碼附TM1616中文PDF與原理圖
TM1616驅(qū)動(dòng)共陰數(shù)碼管接線電路圖

T1616驅(qū)動(dòng)共陰數(shù)碼管源代碼
TM1616.H
- #include <STC12C56.H>
- #include <intrins.h>
- #define clk P10 //定義時(shí)鐘管腳
- #define dio P11 //定義數(shù)據(jù)管腳
- #define stb P37 //定義片選管腳
- #define nop _nop_();
- #define uchar unsigned char
- #define uint unsigned int
復(fù)制代碼TM1616.C
- #include <STC12C56.H>
- #include <intrins.h>
- #include <tm1616.h>
- //---------------------TM1616發(fā)送1字節(jié)數(shù)據(jù)子程序------------------------------------------
- void tm1616write(uchar wr_date)
- {
- uchar i;
- stb =0;
- nop;
- nop;
- for(i=0;i<8;i++)
- {
- clk=0;
- nop;
- nop;
- if(wr_date&0x01!=0)
- {
- dio=1;
- }
- else
- {
- dio=0;
- }
- nop;
- nop;
- clk=1;
- nop;
- wr_date=wr_date>>1;
- }
- }
- //-------------------------TM1616采用固定地址顯示數(shù)據(jù)子程序--------------------------------------------
- void tm1616show(uchar data1,uchar data2,uchar data3,uchar data4)
- {
- uchar j;
- stb = 1;
- clk = 1;
- dio = 1;
- tm1616write(0x00); //顯示模式設(shè)置,設(shè)置為4個(gè)GRID,7個(gè)SEG
- stb=1; //顯示模式設(shè)置完畢,STB置1
- tm1616write(0x44); //數(shù)據(jù)命令設(shè)置,設(shè)置普通模式、固定地址、寫數(shù)據(jù)到顯示寄存器
- stb=1; //數(shù)據(jù)命令設(shè)置完畢,STB置1
- for(j=0;j<4;j++) //4位數(shù)碼管要發(fā)送4次數(shù)據(jù)
- {
- tm1616write(0xC0); //設(shè)置顯示地址1
- tm1616write(data1); //傳輸顯示數(shù)據(jù)1
- stb=1; //顯示數(shù)據(jù)1發(fā)送完畢STB置1
- tm1616write(0xC2); //設(shè)置顯示地址1
- tm1616write(data2); //傳輸顯示數(shù)據(jù)1
- stb=1; //顯示數(shù)據(jù)1發(fā)送完畢STB置1
- tm1616write(0xC4); //設(shè)置顯示地址1
- tm1616write(data3); //傳輸顯示數(shù)據(jù)1
- stb=1; //顯示數(shù)據(jù)1發(fā)送完畢STB置1
- tm1616write(0xC6); //設(shè)置顯示地址2
- tm1616write(data4); //傳輸顯示數(shù)據(jù)1
- stb=1; //顯示數(shù)據(jù)1發(fā)送完畢STB置1
- }
- tm1616write(0x8F); //控制命令設(shè)置,設(shè)置顯示開、顯示最亮
- stb=1; //顯示數(shù)據(jù)發(fā)送完畢STB置1
- }
復(fù)制代碼TM1616主函數(shù)
- #include <STC12C56.H>
- #include <intrins.h>
- #include <tm1616.c>
- #define uchar unsigned char
- #define uint unsigned int
- void ioinit(void)
- {
- P0M0 = 0x00;
- P0M1 = 0x00;
- P1M0 = 0x00;
- P1M1 = 0x00;
- P2M0 = 0x00;
- P2M1 = 0x00;
- P3M0 = 0x00;
- P3M1 = 0xE0;
- }
- void main(void)
- {
- ioinit();
- while(1)
- {
- tm1616show(0x5B,0x66,0x4F,0xFF);
- }
- }
復(fù)制代碼TM1616中文PDF及原理圖源代碼下載
本程序基于stc12c5628單片機(jī) 如KEIL中沒有STC頭文件請(qǐng)自行添加,添加教程可以在本論壇搜索
這個(gè)是對(duì)端口進(jìn)行設(shè)置,根據(jù)需要可以設(shè)置成準(zhǔn)雙向,推挽輸出,輸入,開漏輸出,建議看一下STC的手冊(cè)