ATmega16L-Timer Digital Tube Scanning

Publisher:dswecdLatest update time:2012-08-22 Source: 51heiKeywords:ATmega16L Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
/****************************************
Use timer to maintain digital tube display
Now the digital tube display is increasing.
******************************************/
#include 

unsigned int cnt;
unsigned char shu[8];
unsigned char aa;
const unsigned char duanma[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
                              0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
const unsigned char weima[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};

/******************************************
             Data conversion subfunction
***************************************/
void change(unsigned int i)
{
 shu[0]=duanma[i/1000];
 shu[1]=duanma[i/100%10];
 shu[2]=duanma[i%100/10];
 shu[3]=duanma[i%10];
}

/****************************************
               Delay function
******************************************/
void delay(unsigned int t)
{
   unsigned int x,y;
   for(x=t;x>0;x--)
    for(y=100;y>0;y--);
}

/****************************************
               Display Function
******************************************/
void display(unsigned char i)
{
  PORTB = 0X00;
  PORTA|=0X01;
  PORTA&=0XFE;
  
  PORTB =weima[i];
  PORTA|=0x02;
  PORTA&=0XFD;
  
  PORTB=shu[i];
  PORTA|=0X01;
  PORTA&=0XFE;
}

/******************************************
             Port initialization
***************************************/
void init_port(void)
{
 PORTA=0XFF;
 DDRA=0XFF;
 PORTB=0XFF;
 DDRB=0XFF;
}

/******************************************
             Timer 0 initialization
***************************************/
void timer0_init(void)
{
 TCNT0=0X83; //1MS timing initial value
 TCCR0=0X03; //The timer count pre-division frequency is 64
}

/******************************************
             Timer 0 service function
***************************************/
#pragma interrupt_handler timer0_ovf_isr:10
void timer0_ovf_isr(void)
{
 TCNT0=0X83; //Reinstall the initial timing value of 1ms
 if(++aa>3) aa=0;
  switch(aa)
  {
    case 0: display(0);break;
 case 1: display(1);break;
 case 2: display(2);break;
 case 3: display(3);break;
 default:break;
  }
}

void main(void)
{
 init_port(); //IO port initialization
 timer0_init(); //Timer 1 initialization
 TIMSK=0X01; //Enable T0 interrupt
 SREG=0X80; //Enable general interrupt
 while(1)
 {
  cnt++;
  delay(1000);
  change(cnt);
 }
}
Keywords:ATmega16L Reference address:ATmega16L-Timer Digital Tube Scanning

Previous article:ATmega16L-EEPROM write and read experiment
Next article:ATmega16L-Sports Stopwatch Design

Recommended ReadingLatest update time:2024-11-16 16:03

Pic microcontroller TIMER0 controls the running water lamp
p IC   microcontroller  TIMER0 controls the running water lamp #include pic.h   __CONFIG(0x3B31);  unsigned char num=0,i=0;  void init()  {      TRISB=0x00;      TRISC=0x00;     PORTB=0xFE;      PORTC=0xFE;      }  void TMR0_init()  {      OPTION=0x07; //0 has pull-up resistor 000 0 111 1:256 frequency division       
[Microcontroller]
ATmega16L interrupt sources and interrupt names in GCC
ATmega16L interrupt sources and interrupt names in GCC Interrupt Sources Interrupt Definition Interrupt name SIG_NAME in GCC RESET   Reset interrupt   INT0 External interrupt request 0 SIG_INTERRUPT0 INT1 External interrupt request 1 SIG_INTERRUPT1 TIMER2
[Microcontroller]
Source program for the timer2 clock of 52 single-chip microcomputer to output 500KHz frequency
STC89C52RC can use P1.0 to output a frequency of 500KHz. Here is the source code and the entire project I wrote myself. I hope it can help someone who is interested! The microcontroller source program is as follows: #include reg52.h sfr T2MOD=0xc9; sbit clk_out=P1^0; //clock output void t2_clock(void) { C_T
[Microcontroller]
STM32 uses DMA+DAC+TIMER to output sine wave
I have briefly discussed this before. Based on my personal understanding and knowledge as a rookie, I will review the previous knowledge: DMA: My understanding is a channel, or a bridge. A communication channel between static memory and static memory, or between peripherals and static memory. The advantage of establ
[Microcontroller]
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号