The microcontroller source program is as follows:
#include "stc.h"
#include "button.h"
#include "smg.h"
#include "AT24C02.h"
sbit led1=P0^0;
sbit bell=P0^6;
sbit relay=P0^4;
unsigned char flag_s7,flag_s6;
int money=0,amount=0;//price capacity
unsigned char count,flag_count;
unsigned char state; //Control the two display interface buttons of the digital tube
#define EXE_EN P2 = (P2&0X1F)|0XA0; P2 &= 0X1F
void init_time0() //1 microsecond plus 1
{
TMOD=0x01;
TH0=(65536-50000)/256; //timing 50ms
TL0=(65536-50000)%256;
ET0=1;
//TR0=1;
EA=1;
}
void time0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count==20)
{
count=0;
flag_count=1;
}
}
void key()
{
unsigned char kk=keyboard();
unsigned char guan=get_lux(0x41);
if(guan<64)
{
P0=0xff;
P2&=0x1f;
P2|=0x80;
led1=0; //light l2 is on
P2&=0x1f;
}
if(guan>=64)
{
P0=0xff;
P2&=0x1f;
P2|=0x80;
led1=1; //light l1 off
P2&=0x1f;
}
if(kk==7)
{
flag_s7=1;
state=1;
TR0=1; //Start the timer
}
if(kk==6)
{
flag_s6=1;
state=2;
}
if(flag_s7)
{
flag_s7=0;bell=0;relay=1;EXE_EN;
}
if(flag_s6)
{
TR0=0; //Turn off the timer
flag_s6=0;bell=0;relay=0;EXE_EN;
}
if(state==1)
{
display_s(1,0); display(2,5); display(3,0);
display(4,amount/100); display_s(5,amount%100/10); display(6,amount%10); display(7,0);
}
if(state==2)
{
display_s(1,0); display(2,5); display(3,0);
display(4,money/1000); display_s(5,money%1000/100); display(6,money%100/10); display(7,money%10);
}
if(flag_count==1)
{
flag_count=0;
money=money+5;
amount=amount+1;
}
if(amount==9990){flag_s6=1;state=2;}
}
void main()
{
init_time0();
while(1)
{
key();
}
}
Previous article:MCU smoke alarm program + PCB + schematic diagram
Next article:51 MCU assembly control nRF24L01 source program
- 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
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- ASML predicts that its revenue in 2030 will exceed 457 billion yuan! Gross profit margin 56-60%
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- C8051F340 program runaway problem
- Knowledge points on the classification of commonly used components in RF microwave circuits
- PCB Layout
- Allegro SPB 16.5 version PCB drawing board quick course
- How to enable and disable epwm_isr interrupt
- Share the information of a mini 51 MCU learning board, small and beautiful, with reference programs, schematics and other information
- Test of HDMI audio playback function of Rockchip RK3399 chip development board Orange Pi 4
- I can't believe it: the official routines of C8051F58x_59x also have errors!
- BQ30Z55 bq CHEM (Chemical ID) Configuration
- How to choose the right Cortex-based MCU application design