#include
#include
#define uchar unsigned char
#define uint unsigned int
/***********The corresponding digital tubes display********************/
const uchar table[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned long load=0;
uchar
uint cnt=0;//Number of interrupts in timing
uchar temp=0;//This number is required when it exceeds 65536
//
void display(uchar *p)
{
uchar i,j,sel=0x01;
for(j=0;j<2;j++)
for(i=0;i<4;i++)
{PORTB=~table[p[i]];
PORTC=sel;
Delay_us(2000);
sel=sel<<1;
}
}
void process(unsigned long t,uchar *p)//Data processing
{unsigned long i=t;
if(i<=9999)
PORTD=PORTD|0X03;
else if((i<=99999)&&(i>9999))
{
i=i/100;
PORTD=PORTD&0 XFE;
PORTD=PORTD|0X02;
}
else if(i>99999)
{
PORTD=PORTD|0X01;
PORTD=PORTD&0XFD;
i=i/1000;
}
p[3]=i/1000;
i=i%1000;
p[2]=i/100;
i=i%100;
p[1]=i/10;
i=i%10;
p[0]=i;
}
void int_io(void)
{DDRB=DDRC=0XFF;
DDRD=0XDF;
PORTC=PORTB=0XFF;
PORTD=0XFF;
SREG=0X80;//Global enable
TCCR1B=0X06;//Counting mode: T1 falling edge
TCNT1H=0X00;//Initial value of counter
TCNT1L=0X00;
}
void main(void )
{
int_io();
PORTB=0X00;
PORTC=0XFF;
Delay_ms(500);
PORTB=0XFF;
/****************************/
TCNT0=0X06;//The initial value of timing count is 6
TCCR0=0X04;//T/C0 works in timing mode, system clock is divided by 256
TIMSK=0X01;//Timing local enable T/C0
while(1)
{
process(load,da
display(da
if(TIFR&0X04)//Use the flag bit to handle events when >65536
{ // if(TIFR&0X20)
temp++;
TIFR=TIFR&0X04;
}
}
}
/************************/
////////////////The following is the timer interrupt of T0
#pragma interrupt_handler time0:10
void time0(void)
{
uint tep=0;//Read the value of high word TCNT1L
cnt++;
if(125==cnt)//125*256us, and this is used to adjust the accuracy;
{
cnt=0;//
/********The following is the value of reading the counter***********/
load=0;
load=TCNT1L; //Read the low bit value of the counter
tep=TCNT1H*256; //Read the high bit value of the counter and process it
load=tep+load; //High bit plus low bit
load=load+65536*temp; //Processed data
/***********************/
TCNT1H=0X00;//Reassign initial value
TCNT1L=0X00;
temp=0;
}
}
//TO is used for timing,
Previous article:External asynchronous clock operation
Next article:AVR MCU fuse setting tips
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- KiCad 6.0.0 released
- RF front-end outsourcing
- Boot hardware settings
- 【CODING TALK】How would you implement a queue?
- How to input xy coordinates for hole location in pads packaging
- Strange behavior of Firefox browser
- Detailed explanation of ADC function in C8051F020 microcontroller
- Q and D values of capacitors
- [Nucleo G071 Review] PWM breathing light
- [EETalk] Why do smart homes not use ZigBee but are keen on Bluetooth and Wi-Fi?