Tm1639 assembly driver

Publisher:之敖赵先生Latest update time:2015-07-21 Source: eechinaKeywords:Tm1639 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include
sbit DIO=P1^2;
sbit CLK=P1^1;
sbit STB=P1^0;
#define DIG0 0xc0
#define DIG1 0xc2
#define DIG2 0xc4 
#define DIG3 0xc6
#define DIG4 0xc8
#define DIG5 0xca
#define DIG6 0xcc
#define DIG7 0xce
#define LEVEL_OFF   0x80
#define LEVEL_1     0x88
#define LEVEL_2     0x89
#define LEVEL_4     0x8a
#define LEVEL_10    0x8b
#define LEVEL_11    0x8c
#define LEVEL_12    0x8d
#define LEVEL_13    0x8e
#define LEVEL_14    0x8f
#define MD_WRITE        0x40
#define MD_AUTO         MD_WRITE
#define MD_NORMAL       MD_WRITE
#define MD_READKEY      0x42
#define MD_FIX          0x44
#define MD_TEST         0x48
typedef unsigned char uint8;
typedef unsigned int  uint16;
uint16 key;
code uint8 shuzu[17] ={ 0x3F,0x06,0x5B,0x4F,   
      0x66,0x6D,0x7D,0x07,
      0x7F,0x6F,0x77,0x7c,
      0x39,0x5e,0x79,0x71,
      0x00,     
      
      };   
void xianshi(uint8 x,uint8 led,uint8 level);
void start();
void chushi();
void ClearAll();
void KeyRead(uint16 *key);
void indate(unsigned char input)
{
unsigned int i;

STB=0;               
                      
for(i=0;i<8;i++) {
    CLK=0;            
    if((input & 0x01)!=0)
      PART=1;          
    else
      PART=0;          
    CLK=1;            
    input=input>>1;   
}                   
}
unsigned char outdate()
{
unsigned char i,out=0;   
PART = 1;
STB=0;                                     
for(i=0;i<8;i++) {
    CLK=0;               
    out=out>>1;
    if(DIO == 0)
        out=out & 0x7f;  
    else                 
        out=out | 0x80;
    CLK=1;              
}
return(out);          
}
 
void quit()
{
CLK     = 1;
STB = 1;
PART = 1;
}
 void jishi()
{     
 TMOD |= 0x10;
 TMOD &= 0xdf;
 TH1=0xb8;
 TL1=0x00;
 TR1=1;
 EA=1;
    ET1 = 1;
}
  void ql()
  {
     xianshi(7,0,LEVEL_11);
         xianshi(6,0,LEVEL_11);
  
   xianshi(4,0,LEVEL_11);
   xianshi(3,0,LEVEL_11);
        
   xianshi(1,0,LEVEL_11);
   xianshi(0,0,LEVEL_11);
   
  }
 
 void xianshi(uint8 x,uint8 led,uint8 level)
{
 uint8 i;
 static uint8 cled[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};
  for(i = 0 ;i < 8;i ++ ){
 if((shuzu[led]>>i)&0x01)
  cled[i] |= (0x01<< x);
  else
  cled[i] &= ~(0x01<< x);
 }
 PART=1;
 CLK=1;
 STB=1;                     
 indate(MD_WRITE);
 STB = 1;
 indate(DIG0);
 for( i = 0 ; i<16; i+= 2){
  indate(cled[i/2] & 0x0f);      
  indate(cled[i/2] >> 4 & 0x0f);
 }
 STB=1;                     
 indate(level);
 STB=1;
}

void ClearAll()
{
unsigned int i;           
PART=1;
CLK=1;
STB=1;                     
indate(MD_AUTO);          
STB=1;                    
indate(DIG0);              
for(i=0;i<16;i++)         
      indate ( 0 );             
     
STB=1;                     
indate(0x80);              
STB=1;                     
}
void KeyRead(uint16 *key)
{
unsigned char key1,key2;
STB=1;
indate(MD_READKEY);           
key1 = outdate();
key2 = outdate();
*key = key1 | (key2 << 8);
STB=1;
 
}       
 void delay()
 { uint16 n;
     uint8 k;
  for(k=0;k<10;k++)
  {
 
  for(n=0;n<6000;n++)
 ;
 }
 }
[page]
void zhongduan()interrupt 3
{
shizhong();
}
void start()
{
 static uint16 count=0;
 static uint16 scount=0;
 static uint8  a=0;
 static uint8  b=0;
 static uint8  c=0;
 static uint8  d=0; 
 static uint8  x=0;
 static uint8  y=0;
 TH1=0xb8;
 TL1=0x00;
 count++;
 if(count==5)
 {
     count=0;
  scount++;
x=scount/10%10;
y=scount/100%10; 
 
xianshi(7,x,LEVEL_11);
if(scount%600==0)
{
xianshi(6,0,LEVEL_11);scount=0;a++;
}
else xianshi(6,y,LEVEL_11);
if(a>=10)
{
a=0;b++;
}
xianshi(4,a,LEVEL_11);
if(b>=6)
{
b=0;c++;
}
xianshi(3,b,LEVEL_11);
if(d<2){
if(c==10){
c=0;d++;}
xianshi(1,c,LEVEL_11);
xianshi(0,d,LEVEL_11);}
else if(d>=2){if(d>2)d=0;
if(c==4){
c=0;d=0;}
xianshi(1,c,LEVEL_11);
xianshi(0,d,LEVEL_11);}
 
KeyRead(&key);
if(key==0x0008)a++;
KeyRead(&key);
if(key==0x0080)b++;
KeyRead(&key);
if(key==0x0800)c++;
KeyRead(&key);
if(key==0x8000)d++;
if(key==0x0004){scount=0;
x=0;y=0;}

 
}}
 
 
 
    
 
main()
{
  ql();
  state();
     while(1){};  
Keywords:Tm1639 Reference address:Tm1639 assembly driver

Previous article:MCU 32-port water lamp program
Next article:The role of microcontroller header files

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号