#include
#define uint unsigned int
#define uchar unsigned char
#include "I2C_drive.h" //Includes the I2C bus driver software package
uchar const seg_data[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xff}; //Segment table for 0~9 and the extinguisher
uchar const bit_tab[]={0xbf,0x7f}; //Bit selection table for the 7th and 8th digital tubes
uchar disp_buf[2]={0,0}; //Define 2 display buffer units
uchar val;
#define beep_0 (PORTD=PORTD&0xbf) //The buzzer on PD7 sounds
#define beep_1 (PORTD=PORTD|0x40) //The buzzer on PD7 does not sound
/********Function: Delay function********/
void Delay_ms(uint xms)
{
int i,j;
for(i=0;i
}
/*********The following is a function for the buzzer to sound********/
void beep()
{
uint bb;
for (bb=0;bb<20;bb++)
{
beep_0; //The buzzer sounds
Delay_ms(1);
beep_1; //Turn off the buzzer
Delay_ms(1);
}
}
/********Port setting function********/
void port_init(void)
{
PORTA = 0xFF; //Output high level
DDRA = 0xFF; //Set to output
PORTC = 0xff; //Output high level
DDRC = 0xFF; //Set to output
DDRD =(0<
}
/********Timer 0 initialization********/
void timer0_init()
{
SREG = 0x80; //Enable global interrupt
TIMSK|=(1<
}
/********The following is the display function********/
void Display()
{
uchar tmp; //Define display temporary storage
static uchar disp_sel=0; //Display bit select counter, the display program uses it to know which digital tube is currently displayed, the initial value is 0
tmp=bit_tab[disp_sel]; //Determine which digital tube to display based on the current bit select count value
PORTC=tmp; //Send to PC to control the selected digital tube to light up
tmp=disp_buf[disp_sel]; //Look up the display code of the number based on the current bit select count value
tmp=seg_data[tmp]; //Get the display code
PORTA=tmp; //Send to PA port to display the corresponding number
disp_sel++; //Add 1 to the bit select count value and point to the next digital tube
if (disp_sel==2)
disp_sel=0; //If 2 digital tubes are displayed once, return them to 0 and scan again
}
/********The following is the timer T0 interrupt function, used for dynamic scanning of the digital tube********/
#pragma interrupt_handler timer0_ovf:10
void timer0_ovf(void)
{
TIFR=0x01; //Write 1 to clear the timer T0 flag
TCNT0=240; //Set the initial count value and set the timing time to 2ms
Display(); //Call the display function
}
/********The following is the main function********/
void main()
{
timer0_init();
I2C_init();
port_init();
Delay_ms(100);
val=read_EEPROM(0x02);
if(val>=100) val=0; //Prevent errors when reading EEPROM data for the first time
while(1)
{
if((PIND&0x04)==0) //If K1 key is pressed
{
Delay_ms(10); //Delay 10ms to debounce
if((PIND&0x04)==0)
{
while(!(PIND&0x04)); //Wait for K1 key to be released
val++;
write_EEPROM(val,0x02);
beep();
if(val==99)val=0;
}
}
disp_buf[0]=val/10;
disp_buf[1]=val%10;
}
}
Previous article:C language programming of mega16 internal EEPROM operation based on AVR microcontroller
Next article:C language programming of DS1302 digital tube time display based on AVR microcontroller
- Popular Resources
- Popular amplifiers
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
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- 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
- IC WKN Driver Laser Diode
- Buying analog discovery 2
- Ameya360: Will Intel's latest generation of discrete graphics cards be discontinued?
- Recruiting simulation engineers (software) Annual salary: 200,000-500,000 | Experience: more than 5 years | Work location: Shenzhen
- [Live broadcast on May 9] Discussing solutions to reduce downtime in the new manufacturing era, ADI live broadcast expert Zhao Yanhui is here again
- [Zhongke Bluexun AB32VG1 RISC-V board "run into" RTT evaluation] Software timer + hardware timer
- Why can't the LM2678S-ADJ original be adjusted to 24V after connecting the resistor? I modified the circuit myself (newbie help)
- Must-learn丨PCB inner layer processing steps
- Fancy PCB Exhibition (2)
- [RVB2601 Creative Application Development] player_demo transplantation