|
驅(qū)動(dòng)程序使用的STM32F103的庫寫的
12687e06c004fc5b04255f6359e097df.png (10.07 KB, 下載次數(shù): 183)
下載附件
2020-11-13 16:29 上傳
單片機(jī)源程序如下:
- #include "../HARDWARE/TM1621/TM1621.h"
- #define WRITE PCout(15)
- #define CS PDout(0)
- #define DATA PCout(14)
- //unsigned char Smg[16]={0xad,0xad,0xad,0xad,0x8e,0x8e,0x8e,0x8e,0x8e,0x8e,0x8e,0x8e,0x8e,0x8e,0x8e,0x8e}; //0~F字型碼
- /* 0-0 1-1 15-15 16-空格 17-0x04-負(fù)號 18-0x0B -L */
- unsigned char Smg0[30]={0xeb,0x60,0xc7,0xE5,0x6C,0xAD,0xaf,0xE0,0xef,0xed,0xee,0x2f,0x8b,0x67,0x8f,0x8e,0x00,0x04,0x0B}; //0~F字型碼 //正確字形
- unsigned char Smg1[30]={0xbe,0x06,0x7c,0x5E,0xC6,0xDA,0xFA,0x0E,0xFE,0xDE,0xEE,0xF2,0xB8,0x76,0xf8,0xe8,0x00,0x40,0xB0}; //0~F字型碼 //反向字形
- unsigned char Smg2[30]={0xeb,0x60,0xc7,0xE5,0x6C,0xAD,0xaf,0xE0,0xef,0xed,0xee,0x2f,0x8b,0x67,0x8f,0x8e};
- unsigned char Tab0[30]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //清屏
- /********************延時(shí)函數(shù)*************************/
- void delay_nms(uint n)
- {
- uint i;
- while (n--)
- for (i=0;i<500;i++);
- }
- /********************從高位寫入數(shù)據(jù)*************************/
- void Write_Data_H(uchar Data, uchar Cnt) //Data的高cnt位寫入TM1621,高位在前
- {
- uchar i;
- for (i=0;i<Cnt;i++)
- {
- WRITE=0;
- if (Data&0x80) //從最高位發(fā)送
- DATA=1;
- else
- DATA=0;
- nop;
- nop;
- WRITE=1;
- Data<<=1;
- }
- WRITE=0;
- DATA=0;
- }
- /********************從低位寫入數(shù)據(jù)*************************/
- void Write_Data_L(uchar Data,uchar Cnt) //Data 的低cnt位寫入TM1621,低位在前
- {
- unsigned char i;
- for (i=0;i<Cnt;i++)
- {
- WRITE=0;
- if (Data&0x01) //從低位發(fā)送
- DATA=1;
- else
- DATA=0;
- nop;
- nop;
- WRITE=1;
- Data>>=1;
- }
- WRITE=0;
- DATA=0;
- }
- /********************寫入控制命令*************************/
- void WriteCmd(uchar Cmd)
- {
- CS=0;
- nop;
- Write_Data_H(0x80,4); //寫入命令標(biāo)志100
- Write_Data_H(Cmd,8); //寫入命令數(shù)據(jù)
- CS=1;
- nop;
- }
- /*********指定地址寫入數(shù)據(jù),實(shí)際寫入后4位************/
- void WriteOneData(uchar Addr, uchar Data)
- {
- CS=0;
- Write_Data_H(0xa0,3); //寫入數(shù)據(jù)標(biāo)志101
- Write_Data_H(Addr<<2,6); //寫入地址數(shù)據(jù)(A5-A4-A3-A2-A1-A0)從高位開始寫數(shù)據(jù)
- Write_Data_L(Data,4); //寫入數(shù)據(jù)
- CS=1;
- nop;
- }
- /*********連續(xù)寫入方式,每次數(shù)據(jù)為8位,寫入數(shù)據(jù)************/
- void WriteAllData(uchar Addr,uchar *p,uchar cnt)
- {
- uchar i;
- CS=0;
- Write_Data_H(0xa0,3); //寫入數(shù)據(jù)標(biāo)志101
- Write_Data_H(Addr<<2,6); //寫入地址數(shù)據(jù)
- for(i=0;i<cnt;i++) //寫入數(shù)據(jù)
- {
- Write_Data_L(*p,8);
- p++;
- }
- CS=1;
- nop;
- }
- /***************這個(gè)子程序暫時(shí)沒用,注釋掉******************/
- /*******************TM1621初始化**********************/
- void TM1621_Gpio_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOD |RCC_APB2Periph_GPIOB, ENABLE);//開C口時(shí)鐘,復(fù)用時(shí)鐘。
-
- GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);//使能JTAGDisable,即禁用JTAG接口
-
-
- PWR_BackupAccessCmd(ENABLE);//允許修改RTC 和后備寄存器
- RCC_LSEConfig(RCC_LSE_OFF);//關(guān)閉外部低速外部時(shí)鐘信號功能 后,PC13 PC14 PC15 才可以當(dāng)普通IO用。
- BKP_TamperPinCmd(DISABLE);//關(guān)閉入侵檢測功能,也就是 PC13,也可以當(dāng)普通IO 使用
-
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14 | GPIO_Pin_15;//PC14-Data PC15-WR
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //設(shè)置成輸出
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15 | GPIO_Pin_3;//PB15 - 背光
- GPIO_Init(GPIOB, &GPIO_InitStructure);
-
- GPIO_ResetBits(GPIOB,GPIO_Pin_15);/*低電平開啟背光 高電平關(guān)閉背光*/
-
- GPIO_ResetBits(GPIOB,GPIO_Pin_3);
- GPIO_SetBits(GPIOB,GPIO_Pin_3);
-
-
- GPIO_PinRemapConfig(GPIO_Remap_PD01,ENABLE);/*映射PD01的使能*/
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;//PD0-CS
- GPIO_Init(GPIOD, &GPIO_InitStructure);
-
- PWR_BackupAccessCmd(DISABLE);/* 禁止修改RTC和后備寄存器*/
- BKP_ITConfig(DISABLE);
- }
- void TM1621_init(void)
- {
- TM1621_Gpio_Init();
-
- CS=1;
- WRITE=1;
- DATA=1;
-
- nop;
- delay_nms(1);
- WriteCmd(BIAS); //1/3偏壓 4公共口
- WriteCmd(RC); //內(nèi)部RC振蕩
- WriteCmd(SYSDIS); //關(guān)系統(tǒng)振蕩器和LCD偏壓發(fā)生器
- WriteCmd(WDTDIS); //禁止看門狗
- WriteCmd(SYSEN); //打開系統(tǒng)振蕩器
- WriteCmd(LCDON); //開LCD偏壓
-
- }
- /*************TM1621清屏函數(shù)*****************/
- //void Clear1621()
- //{
- // uchar i;
- // for(i=9;i<22;i++)
- // {
- // WriteOneData(i, 0x00);
- // }
- //}
- /*******************************************************************************
- * 函數(shù)名稱 :1621顯示函數(shù)顯示
- * 函數(shù)功能 :
- * 輸 入 : 無
- * 輸 出 : 無
- *******************************************************************************/
- //void Disp1621(uchar Addr, uchar Data)
- //{
- // WriteOneData(Addr, Data);
- //}
- void Display1621(unsigned char * bmp , unsigned char dot)
- {
- //unsigned char cwDispalyAddress = 11;
- /* 地址 11*/
- /* 數(shù)組bmp第一個(gè)數(shù)據(jù)對應(yīng)顯示最左邊數(shù)碼管 第二個(gè)對應(yīng)第二個(gè)數(shù)碼管 以此類推 */
-
-
- /* void WriteOneData(uchar Addr, uchar Data) */
- /* WriteAllData(uchar Addr,uchar *p,uchar cnt) */
-
- WriteAllData(18,Smg0+(0+bmp[0]),1); //0
-
- WriteAllData(20,Smg0+(0+bmp[1]),1); //1
-
- WriteOneData(22,Smg0[0+bmp[2]]); //2
- WriteOneData(17,Smg0[0+bmp[2]]>>4); //2
-
- WriteAllData(15,Smg1+(0+bmp[3]),1); //3
-
- WriteAllData(13,Smg1+(0+bmp[4]),1); //4
-
- WriteAllData(11,Smg1+(0+bmp[5]),1); //5
- if(RTData[40] == 2) //如果是標(biāo)定界面 則顯示小數(shù)點(diǎn)
- dot = 3;
-
- if(dot != 5){
- if(dot <= 1 ){ //繪制小數(shù)點(diǎn)
- Smg0[bmp[dot]] |= 0x10;
- }else if(dot == 2){
- Smg0[bmp[dot]] |= 0x10;
- }else if(dot > 2){
- Smg1[bmp[dot]] |= 0x01;
- }
-
- if(RTData[40] == 0 || RTData[40] == 2){ // 只有在實(shí)時(shí)值顯示界面和標(biāo)定界面才顯示小數(shù)點(diǎn)
-
- switch(dot)
- {
- case 0:
- WriteAllData(18,Smg0+(0+bmp[0]),1); //0
-
- break;
-
- case 1:
- WriteAllData(20,Smg0+(0+bmp[1]),1); //1
-
- break;
-
- case 2:
- WriteOneData(22,Smg0[0+bmp[2]]); //2
- WriteOneData(17,Smg0[0+bmp[2]]>>4); //2
-
- break;
-
- case 3:
- WriteAllData(15,Smg1+(0+bmp[3]),1); //3
-
- break;
-
- case 4:
- WriteAllData(13,Smg1+(0+bmp[4]),1); //4
-
- break;
- }
-
-
- if(dot <= 1 ){ //繪制小數(shù)點(diǎn)
- Smg0[bmp[dot]] &= 0xef;
- }else if(dot == 2){
- Smg0[bmp[dot]] &= 0xef;
- }else if(dot > 2){
- Smg1[bmp[dot]] &= 0xfe;
- }
- }
- }
- }
- /*
- * @brief 將整型數(shù)轉(zhuǎn)換為字符并顯示
- *
- *
- */
- void DisplayNum(int num , unsigned dot)
- {
- unsigned char cwchar[6]={0,0,0,0,0,0};
- u8 b[6];
- u8 j=0,k=0,m;
- int i;
-
- if(num>999999)
- num=999999;
- if(num<-99999)
- num=-99999;
-
- if(num>=0){
- b[5]=0;//正數(shù)
- }
- else{
- num=-num;
- //num[0]=45;
- b[5]=1;//負(fù)數(shù)
- }
- for(i=5 ; i>=0 ; i--){ //整型數(shù)轉(zhuǎn)字符數(shù)
-
- if(num!=0) //判斷是否
- cwchar[i]=(num%10);
- else{ //無數(shù)字
- if(j==0)j=i; //數(shù)據(jù)位數(shù)
-
- if(!b[5]){
- if((dot<5-i)) //&&(RTData[11]!=2&&RTData[11]!=3)&&RTData[13]!=2
- cwchar[i]=16;
- }else{
-
- if((dot<5-i)){ //&&(RTData[11]!=2&&RTData[11]!=3)&&RTData[13]!=2
- cwchar[i]=16;
- if(k==0)
- k=i;//負(fù)數(shù)小數(shù)點(diǎn)首位位數(shù)定位
- }
- }
- }
- num/=10;
- }
- ……………………
- …………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
只需要將關(guān)鍵引腳替換即可正常使用
TM1621.zip
(3.52 KB, 下載次數(shù): 305)
2020-11-13 16:25 上傳
點(diǎn)擊文件名下載附件
驅(qū)動(dòng) 下載積分: 黑幣 -5
根據(jù)下圖和TM1621的引腳更換其顯示腳
|
評分
-
查看全部評分
|