//***************ICCAVR V6.30 compiled*****************//
#include
#define uchar unsigned char
#define uint unsigned int
//Digital tube font table, corresponding to 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 //
uchar Table[10]={0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
uchar
uchar Key1_Flag, Key2_Flag, Key3_Flag;
void DelayMs(uint i) //Ms level delay, parameter i is the delay time
{uint j;
for(;i!=0;i--)
{for(j=8000;j!=0;j--) {;}}
}
void Display(uchar *p) //dynamic display function, parameter p is the name of the array to be displayed
{uchar i,sel=0x01;
for(i=0;i<4;i++)
{PORTA=sel; //select the rightmost digital tubePORTC
=0xff-Table[p[i]]; //send font code
DelayMs(1); //display delay
sel=sel<<1; //shift to display the previous digit
}
}
void Key_Process(uchar *p)
{uchar i,j,k;
while((PINB&0x01)==0) {Display(Da
while((PINB&0x02)==0) {Display(Da
while((PINB&0x04)==0) {Display(Da
if(Key1_Flag==1)
{p[3]++;
if(p[3]==10) p[3]=0;
Key1_Flag=0;}
if(Key2_Flag==1) //Processing frequency tens, up to 9
{p[2]++;
if(p[2]==10) p[2]=0;
Key2_Flag=0;}
if(Key3_Flag==1) //Processing frequency every digit, up to 9
{p[1]++;
if(p[1]==10) p[1]=0;
Key3_Flag=0;}
}
void Set_Process(void)
{uint i,j;
i=Da
j=500/i;
OCR1AH=j>>8;
OCR1AL=j&0x00ff;
}
void Init_IO(void) //Initialize I/O port
{DDRA=0xff; //Set port A to push-pull 1 output
PORTA=0xff;
DDRC=0xff; //Set port C to push-pull 1 output
PORTC=0xff;
DDRB=0x00; //Set port B to tri-state input
PORTB=0x00;
DDRD=0xff; //Set port D to push-pull 1 output
PORTD=0xff;
}
void Init_Timer1(void) //Initialize the input capture interrupt of T/C1
{TIMSK=TIMSK|0x10; //Output compare enable
TCCR1B=0x0a; //Clock 1 frequency, output compare match clear timer value
TCNT1H=0x00; //Clear timer value
TCNT1L=0x00;
Set_Process(); //OCR1A,OCR1B initial value
SREG=SREG|0x80; //Global disconnect
}
void main(void)
{Init_IO(); //Initialize I/O port
PORTA=0xff; //Light up to test all digital tubes
PORTC=0x00;
Init_Timer1();
DelayMs(300); //Delay
PORTC=0xff; //Turn off all digital tubes
while(1)
{Key_Process(
Set_Process();
Display(
}
}
#pragma interrupt_handler Compare:7
void Compare(void)
{PORTD=~PORTD;}
Previous article:Design of frequency meter based on tc1
Next article:Clock design based on tc0
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- How to install virtual machine on SinA33 development board
- Newbie asks for advice on STC89c54RD+, RAM access value application
- The problem of sensor sampling value software returning to zero
- Several indoor wireless positioning technologies
- NXP Rapid IoT Review] +4. Learn the design ideas of POWER circuits
- HTS221 self-heating function test
- Understanding the configuration of C2000 series CMD files
- [Xiaomeige SoC] Generate preloader under win10 and report Failed to open gdrive/…/uboot-socfpga.tar.gz
- Looking for a voltage detection circuit or chip, 3v to 12v
- You must call ros::init() before creating the first NodeHandle