C code for making eye-activating instrument with single-chip microcomputer

Publisher:太白山人Latest update time:2012-11-24 Source: 21IC Keywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

This is a complete code of the eye-activating instrument made with 51 series single-chip microcomputer. Friends who need it can take a look. The code has been tested successfully.
/*
Project name: Single-chip eye-activating instrument
Related knowledge points: single-chip microcomputer drives heating devices, digital tube display, key operation, etc.
Program development: http://www.51hei.com single-chip microcomputer tutorial website.
*/
#include
#define uint unsigned int
#define uchar unsigned char
#define duan P0 // Define the segment display of P1 port as duan label
#define keyio P3 // Set P3 port as the port for key detection

uchar time,guannum,guantime1,guantime2; //time is the value in minutes, light displays the time value
uint b; //50MS is 1 time, so 1 minute is 1200 times
bit xsd,onandoff; //decimal point flashing bit variable, switch variable flag bit

sbit xuanled=P2^3;
sbit guanled=P2^5;
sbit rfled=P2^7;//Three indicator light position control
sbit xsdbit=P0^6;//Decimal point actual hardware output pin definition
sbit gewela=P2^0;//Ones digit digital tube position control
sbit shiwela=P2^1;//Tens digit digital tube lock position control
sbit guanout=P1^0;//Spectrum output
sbit rfout=P1^1; //RF heating head output drive
sbit xuanout=P1^2; //Gyromagnetic output
sbit fmqout=P1^3;


uchar code tab[]={0x48,0xee,0x54,0x64,0xe2,0x61,0x41,0xec,0x40,0x60,0xf7};//Digital tube segment display code 0~9, to be written
void chushi(void); //Initialize when entering the main function
void key(void); //Key detection
void display(uchar time);//Digital tube display processing program
void chushi1(void); //Perform large loop function initialization processing

void delay(uchar num)//delay module program
{
uchar c,d;
for(c=num;c>0;c--)
for(d=40;d>0;d--);
}


void main() //Main function program body
{
uchar a;
chushi();

while(1)
{
chushi1();
key(); //Key detectionif
(keyio!=0xff)
fmqout=0;
else fmqout=1;
if(onandoff!=0)
{
for(a=100;a>0;a--)
{
duan=tab[10]; //Open segment display, display the middle segment
gewela=0;
shiwela=0;
delay(10);
gewela=1;
shiwela=1;
}

while(onandoff!=0)
{
display(time);
key();
if(time==0&&b>=1000)
fmqout=xsd;
else if(keyio==0xff)
fmqout=1;
else fmqout=0;

}
for(a=200;a>0;a--)
display(time);
}
}

}

void time0() interrupt 1
{
TH0=0x3c;
TL0=0xb0;
b++;
if(b==1200)
{
b=0;
if(time!=0)
time--;
else onandoff=0; //set zero flag
}

if(b%10==0)
xsd=~xsd; //The decimal point variable changes in a cycle of 1S
if(guannum==2||guannum==3)
{
guantime2--;
if(guantime2==0)
{
guantime2=guantime1;
guanout=~guanout;
}
}
}[page]

void chushi(void) //Initialize directly when entering the main MAIN function body
{
TMOD=0x01; //Timer timing mode
TH0=0x3c;
TL0=0xb0;
ET0=1;
EA=1;
TR0=1;
xuanled=1;
guanled=1;
rfled=1;
}

void chushi1(void) //Initialization of the large loop
{
time=30; //The initial time value is 30 minutes when the machine is turned on

guanout=0; //Spectrum output is low level
rfout=0; //RF heating head output drive is low level
xuanout=0; //Gyromagnetic output low level
guannum=0; //When in standby mode, the spectrum is in 0 state

xuanled=1;
guanled=1;
rfled=1;


duan=tab[10]; //Open segment display, display the middle segment
gewela=0;
shiwela=0;
delay(2);
gewela=1;
shiwela=1;
}


void key(void) //Key detection module
{
uchar a,num1;
keyio=0xff;
if(keyio!=0xff)
{
fmqout=0;
if(onandoff!=0)
{
for(a=100;a>0;a--)
display(time);
}
else
{ for(a=20;a>0;a--)
{
duan=tab[10]; //Open segment display, display the middle segment
gewela=0;
shiwela=0;
delay(2);
gewela=1;
shiwela=1;
}
}
if(keyio!=0xff)
{
num1=keyio;
switch(num1)
{
case 0xfe: onandoff=~onandoff; //Switch on and off
break;

case 0xfd: b=0;
if((onandoff!=0)&&(time!=99)) //time plus
time++;
break;

case 0xfb: b=0;
if((onandoff!=0)&&(time!=0)) //time minus
time--;
break;

case 0xf7: if(onandoff!=0)
{
xuanout=~xuanout; //rotation variable changeif
(xuanout!=0)
xuanled=0;
else xuanled=1;
}
break;

case 0xef: if(onandoff!=0) //spectral output variable changes
{
guannum++;
if(guannum==4)
guannum=0;

if(guannum!=0)
guanled=0;
else guanled=1;

if(guannum==1)
guanout=1;
else if(guannum==2)
guantime1=guantime2=15;
else if(guannum==3)
guantime1 =guantime2=8;
else guanout=0;

}
break;
case 0xdf: if(onandoff!=0) //RF heating variable changes
{
rfout=~rfout;
if(rfout!=0)
rfled=0;
else rfled=1;
}
break;
default:break;


}
}

}
}


void display(uchar min) //digital tube display module
{
uchar ge,shi;
shi=min/10;
ge=min%10;

duan=tab[shi];
shiwela=0;
delay(5);
shiwela=1;

duan=tab[ge];
xsdbit=xsd;
gewela=0;
delay(5);
gewela=1;
}

Keywords:MCU Reference address:C code for making eye-activating instrument with single-chip microcomputer

Previous article:Single chip microcomputer controls thyristor dimming without lightning circuit + program
Next article:About the PxM0 and PxM1 settings of the STC12C5410AD microcontroller

Recommended ReadingLatest update time:2024-11-16 14:51

PIC microcontroller sleep low power debugging record
Before executing the sleep() function, you can set the unused pins to analog input, high impedance mode. ANSELAbits.ANSA4 = 1; //Before entering sleep, set the LED IO port to analog input TRISAbits.TRISA4 = 1;  If set to digital input, the power consumption will increase, about 40uA (single IO) ANSELAbits.ANSA4
[Microcontroller]
Homemade simple and practical 51 single chip microcomputer development board
1. Circuit Principle The circuit is shown in the figure below. The P0 port of the 89S52 single-chip microcomputer is connected to the data line of the 1602 character LCD screen with an external 8x1kΩ pull-up resistor. P2.5, P2.6, and P2.7 are connected to the three control lines of the 1602 character LCD screen to for
[Microcontroller]
Homemade simple and practical 51 single chip microcomputer development board
51 MCU Learning——8.2--Timer Counter
Timing counter principle CPU Timing Oscillation period: The period of the oscillation source that provides the timing signal for the microcontroller (crystal oscillator period or external oscillation period) State cycle: 2 oscillation cycles are 1 state cycle, represented by S. The oscillation cycle is also called t
[Microcontroller]
51 MCU Learning——8.2--Timer Counter
Microcontroller Knowledge Series-1-485 Communication
1. The origin of RS-485 communication RS-232, RS-422 and RS-485 are all serial data interface standards, which were originally formulated and issued by the Electronic Industries Association (EIA). RS-232 was issued in 1962 and named EIA-232-E as an industrial standard to ensure compatibility between products of diff
[Microcontroller]
Microcontroller Knowledge Series-1-485 Communication
AVR microcontroller read and write clock chip DS3231 program (passed the test)
The real-time clock chip DS3231 is the world's most accurate integrated chip and the first chip in the industry to use a simple tuning fork crystal and integrated circuit to provide ±2 minutes/year time keeping accuracy. //The program is rewritten from the AT24C series read and write program, the only difference is
[Microcontroller]
How to distinguish the internal crystal oscillator and external crystal oscillator of the microcontroller
  1. Brief introduction of single chip microcomputer crystal oscillator   The crystal oscillator of the microcontroller is a component that generates the clock frequency required by the microcontroller's internal circuit. The higher the clock frequency provided by the microcontroller crystal oscillator, the faster t
[Microcontroller]
Discussion on PL2303 for STC microcontroller download
Tested STC MCU: STC12LE5A60S2 USB to serial port chip: PL2303HX (version E or F) Test environment: Win7 mainly   I believe that many people will encounter problems when using the USB to serial port chip PL2303, such as low baud rate, inability to download, etc. I also have been working on it for a long time, alt
[Microcontroller]
Pure software realizes remote communication of microcontroller
GMS972051 is a MCS-51 compatible microcontroller with 2K E2PROM inside the MW produced by South Korea's LG Company. GMS97C2051 eliminates the P0 and P3 ports of MCS-51, but adds an internal hardware comparator. Since the communication signal of the microcontroller is TTL level, if no other measures are taken, the comm
[Industrial Control]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号