99-minute countdown program with relay output

Publisher:cloudy德德Latest update time:2022-03-14 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#include //Maximum 99 minutes countdown reminder


#define uchar unsigned char

#define uint unsigned int

sbit gewei0=P1^6; //Allow units digit display.

sbit shiwei0=P1^7; //Allow tens digit display.

sbit key1=P1^2; //Key 1, each press adds 10 minutes.

sbit key2=P1^1; //Key 2, each press adds 1 minute.

sbit key3=P1^0; //Key 3, start countdown or pause.

sbit beep=P1^3; //buzzer

sbit led=P1^4; //second indicator light

sbit jdq=P3^4; //relay

uchar k;

unsigned int s,m;

void delayms(uchar);

void delay(uint z);

void keyscan();

void display(uchar);

void init();

void xiang1();

void xiang2();

uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};


void main()

{ init(); //Call "initialization".

while(1)

{ keyscan(); //Adjust "monitoring keys".

display(k); //Adjust "display".

}}


void keyscan() //Monitor keys.

{ if(key20)

{ delayms(26);

if(key20)

{ k++;

if(k>=99) //k==99 is consistent with the interrupt.

k=0;

while(!key2); //When key2 is released, the result of k+2 is displayed.

}

}


if(key10)

{ delayms(26);

if(key10)

{ k=k+10;

if(k>=99) //k99 is consistent with the interrupt.

k=0;

while(!key1);

}

}

if(key30)

{ delayms(26);

if(key3==0)

{

xiang1(); //Start the "countdown" prompt.

delayms(246);

TR0=~TR0;

jdq=~jdq; //Relay status flips with the start/stop button

while(!key3);


}}}


void delayms(uchar z) //delay.

{ uchar i,j;

for(i=z;i>0;i–)

for(j=110;j>0;j–); }


void delay(uint z)

{ while(z–); }


void display(uchar k) //Display.

{ uchar shi,ge;

shi=k/10;

ge = k%10;


gewei0=0;

P2=table[ge];

delayms(21);

gewei0=1;


shiwei0=0;

P2=table[shi];

delayms(21);

shiwei0=1;

}


void init() // Initialization. Set the interrupt and timer values.

{ TMOD = 0x01;

TH0=(65536-50000)/256; //Crystal oscillator 12MHz, timing 50ms.

TL0=(65536-50000)%256;

EA=1;

ET0=1;

}


void xiang1() //Timer starts prompt tone.

{undefined

uchar q;

for(q=0;q<100;q++)

{undefined

beep=0;

delayms(6);

beep=1;

delayms(4);

}

delayms(64);

}


void xiang2() //Timeout reminder sound – beep.

{undefined

unsigned int m;

uchar n,i;

for(i=3;i>0;i–)

{undefined

for(n=123;n>0;n–)

{undefined

beep=0;

delay(100);

beep=1;

delay(100);

}


for(m=3456;m>0;m–);

for(n=123;n>0;n–)

{undefined

beep=0;

delay(90);

beep=1;

delay(90);


}

1

for(m=56789;m>0;m–);


}


}


void time0()interrupt 1 //0 interrupt, interrupt number 1.

{ uint zxc=65432;

TH0=0xb1; //Crystal oscillator 12MHz, timing 20ms.

TL0=0xe0;

s++;

if(m25) //Indicate seconds.

{

m=0;

led = ~led;}

m++; //uchar m; defined as a global variable.

if(s3000) //3000×20ms=60000ms÷1000ms=60s(1 minute)

{ s=0; //Reset to zero. Wait for the next 1 minute.

k–; } //Countdown, minus 1 minute.


if(k<=0) //If it reaches 0, make a sound and turn off the interrupt.

{undefined

k=0;

xiang2();


TR0=0; //When the scheduled time is up, turn off interrupt 0 and stop.

jdq=1; //Relay release


}}

Reference address:99-minute countdown program with relay output

Previous article:Single chip incandescent lamp dimming program
Next article:C51 single chip microcomputer independent button

Recommended Content
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号