Advanced Functions and Keys

Publisher:EuphoricVoyageLatest update time:2024-08-22 Source: cnblogs Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Function Call

If a function is written after the main function, the function must be declared before the main function.

Actual parameters: the parameters in the brackets when calling a function

Formal parameters: The function is defined when the function is called, and the parameters in the brackets are called formal parameters.

Key debounce: When a key is pressed, there will be jitter, and a delay of 10ms is required

#include

sbit ADDR0 = P1^0;
sbit ADDR1 = P1^1;
sbit ADDR2 = P1^2;
sbit ADDR3 = P1^3;
sbit ENLED = P1^4;

sbit KEY4 = P2^7;

unsigned char code LedChar[]={
0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8,
0x80, 0x90, 0x88, 0x83, 0xC6, 0xA1, 0x86, 0x8E
};

bit KeySta = 1;

void main()
{
bit backup = 1;
unsigned char cnt = 0;

EA = 1;
ENLED = 0;
ADDR3 = 1;
ADDR2 = 0;
ADDR1 = 0;
ADDR0 = 0;
TMOD = 0x01;
TH0 = 0xF8;
TL0 = 0xCD;
ET0 = 1;
TR0 = 1;
P2 = 0xF7;
P0 = LedChar[cnt];

while(1)
{
if(KeySta != backup)
{
if(backup == 0)
{
cnt++;
if(cnt >= 10)
{
cnt = 0;
}
P0 = LedChar[cnt];
}
backup = KeySta;
}

}
}

void InterruptTimer0() interrupt 1
{
static unsigned char keybuf = 0xFF;

TH0 = 0xF8;
TL0 = 0xCD;

keybuf = (keybuf <<1) |KEY4;
if(keybuf == 0x00)
{
KeySta = 0;
}
else if(keybuf == 0xFF)
{
KeySta = 1;
}
else
{
}

}


Reference address:Advanced Functions and Keys

Previous article:Stepper motor and buzzer
Next article:[51 MCU] Matrix keyboard line-by-line scanning simulation experiment + ultra-detailed Proteus simulation and Keil operation steps

Latest Microcontroller Articles
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号