/*************************************Include header file********************************/
#include
#include
/************************************Digital tube segment code table*******************************/
extern const unsigned char tab[]={0x3f,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,
0x7F,0x6F};
/*************************************Port definition**********************************/
#define sclon PORTG |= BIT(0); // Clock high
#define scloff PORTG &=~BIT(0);
#define dion PORTG |=BIT(1); //Data high
#define dioff PORTG &=~BIT(1);
/*************************************Global variables**********************************/
unsigned int adc_rel;
int that;
/****************************************************************************
Function: ADC initialization function
Entry parameters:
Export parameters:
****************************************************************************/
void adc_init(void)
{
ADCSRA=0x00; //turn off ADC
ADMUX = (1<
ADCSRA = (1<
ADSC)|(1< }
/****************************************************************************
Function: ADC interrupt function
Entry parameters:
Export parameters:
****************************************************************************/
#pragma interrupt_handler adc_isr:iv_ADC
void adc_isr(void)
{
int data_H,data_L;
ADCSRA = 0x00;
adc_rel=ADC;
ADCSRA = (1<
}
/****************************************************************************
Function: Data output program
Entry parameter: temp
Export parameters:
****************************************************************************/
void dataOUT(unsigned char temp)
{
unsigned char i,temp1;
temp1 = tab[temp];
for(i = 0;i < 8;i++ )
{
scloff;
IF((temp1&0x80)!= 0x80)
{ dioff;}
else
{ dion;}
sclon;
temp1 <<=1;
scloff;
}
}
/****************************************************************************
Function: Delay subroutine
Entry parameters:
Export parameters:
****************************************************************************/
void delay(void)
{
int i;
for(i=0;i<200;i++);
}
/****************************************************************************
Function: Display subroutine
Entry parameter: k
Export parameters:
****************************************************************************/
void display(unsigned int k)
{
dataOUT(k/1000);
PORTG &=0x03;
delay();
dataOUT(k/100%10);
PORTG |=0x04;
delay();
dataOUT(k/10%10);
PORTG &=0x0B;
PORTG |=0x08;
delay();
dataOUT(k%10);
PORTG |=0x0C;
delay();
}
/****************************************************************************
Function: Main program
Entry parameters:
Export parameters:
****************************************************************************/
void main(void)
{
DDRE=0x00;
DDRG=0xff;
adc_init();
BE();
display(0);
while(1)
{
delay();
display(adc_rel);
}
}
Previous article:Design of museum anti-theft protection system based on AVR microcontroller
Next article:Embedded Controller Designed Based on Atmega128 Single Chip Microcomputer
- 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
- How to deal with electromagnetic compatibility issues during single chip microcomputer design
- Modified booster plate + purifier
- Power supply fluctuation problem of portable equipment
- RFID antenna connector classification
- EEWORLD University Hall----Live Replay: Metaverse Testing Seminar Series: Challenges of VR/AR Digital Interface Testing
- CCS5 connection debugging C64X series DSP core
- Help! How to convert assembly language into C language? ? ?
- 【MSP430】Capture mode to measure signal duty cycle
- Short-range wireless positioning technology
- In addition to the cost of electronic components, what other costs are there in hardware product development?