The interrupt debugging program of PIC microcontroller AD conversion is as follows (without digital filtering):
#include
#define uchar unsigned char
#define uint unsigned int
__CONFIG(0x3B31);
const uchar disp[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uint adval;
float advalf;
uchar flag;
void delayms(uint x)
{
uint j,k;
for(j=x;j>0;j--)
for(k=110;k>0;k--);
}
void display(uint x )
{
PORTD= disp[x/1000]|0x80;
PORTA= 0xF1;
delayms(1);
PORTD= disp[x/100%10];
PORTA= 0xF3;
delayms(1);
PORTD= disp[x/10%10];
PORTA= 0xF5;
delayms(1);
PORTD= disp[x%10];
PORTA= 0xF7;
delayms(1);
}
void init()
{
uint adval=0;
float advalf=0;
flag = 0;
TRISA=0x01;
TRISC=0;
PORTC=0x01;
TRISD=0;
ADCON0=0x41; //8-division (4M), AN0, enable ADC
ADCON1=0x8E; //right-align, AN0 channel
ADRESH = ADRESL = 0;
PIE1 |=0x40; //AD interrupt enable
INTCON |= 0xC0; //Peripheral enable, global interrupt enable
ADGO=1; //ADC conversion enable
delayms(10);
}
void interrupt AD(void)
{
if(ADIF&&ADIE) //AD interrupt enable and flag bit set
{
ADIF = 0; //flag bit reset
ADGO=0; //Pause AD conversion
flag = 1; //Set flag bit
}
}
void main()
{
init();
while(1)
{
if(flag)
{
flag = 0;
adval=ADRESH;
adval=adval<<8|ADRESL;
advalf=adval/1023.0*5.0;
adval=advalf*1000;
ADGO=1; //ADC转换使能
display(adval);
}
}
}
Previous article:Analysis of PIC16F877 Asynchronous Serial Port Interrupt
Next article:PIC16F877A internal EEPROM reading and writing experiment
- 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
- 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
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- Here is a 555 timer simulation, the output is adjustable duty cycle (less than 50%), the previous simulation, but this simulation is wrong...
- Code efficiency in TMS320F28377S Flash and RAM
- [Xianji HPM6750EVKMINI Review] 3# HPM6750 Control of RW007 Module
- Question about transistor base emitter saturation voltage
- Problems with switching tube oscillation and inversion
- Can this be done at the input end of the optocoupler?
- KiCad 5.1.6 released
- [Jiangxiang Technology] Today I won a bottle of 2499 Jiangxiang Technology
- Today at 10:00 AM, live broadcast with prizes: Arrow Electronics & ADI join hands to design flyback isolated power supply without optocoupler
- I heard that Shengbang’s products are very popular recently. What do netizens think?