找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 8065|回復: 3
收起左側(cè)

PIC單片機驅(qū)動TM1616源程序

[復制鏈接]
ID:311518 發(fā)表于 2018-4-19 11:02 | 顯示全部樓層 |閱讀模式
/*本程序適用于沒有SIP功能的單片機添加SIP發(fā)送功能*/
#include<pic.h>
__CONFIG(0x1832);        
//芯片配置字,看門狗關(guān),上電延時開,掉電檢測關(guān),低壓編程關(guān),加密,4M晶體HS振蕩 #define clk P10                                        //定義時鐘管腳
#define clk RC3         //定義時鐘管腳
#define dio RC5        //定義數(shù)據(jù)管腳
#define stb RC2        //定義片選管腳
//#define nop _nop_();
#define uchar unsigned char
#define uint  unsigned int
const char TABLE[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,
                    0x77,0x7c,0x39,0x5e,0x79,0x71,0xE0,0x5C,0x3E,0x78,
                    0x37, 0x76, 0x38, 0x01, 0x41, 0x49,0x00};

unsigned char store_bank[4];  //建立數(shù)據(jù)列隊3
//初始化函數(shù)體
void init()
   {
     ADCON1=0X07;
     TRISA=0X30;
     TRISB=0X03;
     TRISC=0X10;
     TRISD=0X00;
     PORTD=0XFF;
//    SSPSTAT=0X80;
//    SSPCON=0X31;
     INTCON=0X00;
     PIR1=0X00;
     stb=0;
   }
//---------------------TM1616發(fā)送1字節(jié)數(shù)據(jù)子程序------------------------------------------
void tm1616write(uchar wr_date)
{
        uchar i;
        stb =0; //片選管腳
        NOP();
        NOP();
        for(i=0;i<8;i++)//循環(huán)運行8次
        {
                clk=0;  //時鐘管腳
                NOP();
                NOP();
                if(wr_date&0x01!=0)//查看數(shù)據(jù)的最小位是否為0
                {
                        dio=1; //數(shù)據(jù)管腳
                }
                else
                {
                        dio=0;//數(shù)據(jù)管腳
                }
                NOP();
                NOP();
                clk=1;  //時鐘管腳
                NOP();
                wr_date=wr_date>>1;//數(shù)據(jù)左移1位
        }        
}
//-------------------------TM1616采用固定地址顯示數(shù)據(jù)子程序---------------------------------
void tm1616show(uchar data1,uchar data2,uchar data3,uchar data4)
{       uchar j;
        stb = 1;  //片選管腳
        clk = 1;  //時鐘管腳
        dio = 1;  //數(shù)據(jù)管腳
        tm1616write(0x00); //顯示模式設(shè)置,設(shè)置為4個GRID,7個SEG
        stb=1;      //片選管腳       //顯示模式設(shè)置完畢,STB置1
        tm1616write(0x44); //數(shù)據(jù)命令設(shè)置,設(shè)置普通模式、固定地址、寫數(shù)據(jù)到顯示寄存器
        stb=1;   // 片選管腳//數(shù)據(jù)命令設(shè)置完畢,STB置1
                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
}
//T毫秒延時程序'''''''''''''''''''''''''''''''''''''''''''
void  DELAY(unsigned int t )              //延時程序
    {unsigned int y;
     while(t)
     {
     for(y=98;y--;);     //延時
     t--;
    }}
//運算------------------------------------
void count(uint y)
  {uchar ca;
   ca=y/0x64/0xa;    //求千位數(shù)/100=10數(shù)據(jù)/10等于一個千位數(shù)字 余數(shù)扔掉
   store_bank[3]=TABLE[ca];
   ca=(y/0x64)%0xa;    //千位數(shù)/100留下百位以下數(shù)據(jù)
   store_bank[2]=TABLE[ca];
   ca=(y%0x64)/0xa;     //求顯示的個位
   store_bank[1]=TABLE[ca];
   ca=(y%0x64)%0xa;     //求顯示的個位
   store_bank[0]=TABLE[ca];
  }           
//TM1616主函數(shù)體---------------------------------------------
void main(void)
{ uint k;
   init();
        while(1)
        { for(k=0;k<9999;k++)
              {count(k);
                tm1616show(store_bank[3],store_bank[2],store_bank[1],store_bank[0]);  //帶數(shù)據(jù)
                 DELAY(50);
              }   

回復

使用道具 舉報

ID:68585 發(fā)表于 2018-6-22 09:13 | 顯示全部樓層
很好啊。
回復

使用道具 舉報

ID:619604 發(fā)表于 2019-10-17 22:39 | 顯示全部樓層
看看是否用的
回復

使用道具 舉報

ID:619604 發(fā)表于 2019-10-17 22:39 | 顯示全部樓層
看看是不是好東東
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表