#include
__CONFIG(0x1832);
const char TABLE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0X82,0XF8,0X80,0X90}; //Define the data table of constants 0-9
volatile unsigned char result=0,temp=0,f=0;
volatile unsigned int total=0,ge=0,shi=0,bai=0,qian=0,c=1;
void delay(); //delay function declaration
void init(); //I/O port initialization function declaration
void s CAN (); //Key scanning program declaration
void display(unsigned int x); //Display function declaration
//---------------------------------------------------
//Main program
void main()
{
init(); //Call initialization subroutine
while(1) //Loop work
{
scan();
display(result);
}
}
//---------------------------------------------------
//Initialization function
void init()
{
ADCON1=0X07; //Set port A as a normal I/O port
TR ISA =0B00000000; //Set the high 2 bits of port A to output and the low 4 bits to input
TRISC=0B11110000; //Set the high 4 bits of port C as input and the low 4 bits as output
TRISD=0X00; //Set port D as output
PORTA=0XFF;
PORTD=0XFF; //Clear all displays first
}
//-----------------------------------------------3---
//Key scanning program
void scan(){
PORTC=0xff;
RC3=0; { if(RC4==0) result=1; if(RC5==0) result=2; if(RC6==0) result=3; if(RC7==0) result=4;}
PORTC=0xff;
RC2=0; { if(RC4==0) result=5; if(RC5==0) result=6; if(RC6==0) result=7; if(RC7==0) result=8;}
PORTC=0xff;
RC1=0; { if(RC4==0) result=9; if(RC5==0) result=10; if(RC6==0) result=11; if(RC7==0) result=12;}
PORTC=0xff;
RC0=0; { if(RC4==0) result=13; if(RC5==0) result=14; if(RC6==0) result=15; if(RC7==0) result=16;}
// if(temp!=result) {f++; if(f==1) qian=1000*result ; if(f==2) bai=100*result; if(f==3) shi=10*result; if(f==4) ge=result; } if(f==4) while(1){total=ge+shi+bai+qian; display(total); }
}
//----------------------------------------------------------------
//Display program
void display(unsigned int x) // Voltage display function
{
unsigned int g,s,b,q; //define 6 temporary variables
// temp=result; c=1;
q=x/1000;
b=x%1000/100; //find the thousands displayed
s=x%100/10; //find the hundreds displayed
g=x%10; //find the tens displayed
PORTD=TABLE[q]; //display a decimal point
PORTA=0B111111110; //RA0 output lowlevel , light up the thousands display
delay(1);
PORTD=TABLE[b]; //Look up the table to get the code for the hundreds display
PORTA=0B11111101; //RA1 outputs low level, light up the hundreds display
delay(1); //Delay for a certain time to ensure the display brightness
PORTD=TABLE[s]; //Look up the table to get the code for the tens display
PORTA=0B11111011; //RA2 outputs low level, light up the tens display
delay(1); //Delay for a certain time to ensure the brightness
PORTD=TABLE[g]; //Look up the table to get the code for the tens display
PORTA=0B11110111; //RA3 outputs low level, light up the tens display
delay(1); //Delay for a certain time to ensure the brightness
PORTD=0xff;
}
//------------------------------------------------------------------
//Delay program
void delay() //Delay program
{
int i; //Define integer variables
for(i=0x100;i--;); //Delay
}
Previous article:LCD1602 C Program
Next article:PIC microcontroller LED water light program
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- Actual op amp parameters
- 2. Main knowledge points of previous "power supply" competition questions
- PCB Design Issues
- Professor Yang's book is here, a five-volume collection of "New Concept Analog Circuits" series by Yang Jianguo of Xi'an Jiaotong University
- There is a 4Mhz signal. After passing through the detection diode, how to effectively filter out 4MHz and the 2nd, 3rd, and 4th harmonics.
- Toshiba Photorelay Evaluation - Dynamic Characteristics Test
- FPGA_100 Days Journey_Electronic Piano Design
- 2019, what is your New Year's resolution?
- Autobot Badge
- Dealing with transient issues in the power stage of driver integrated circuits