功能:
0.本项目采用STC89C52作为单片机系统的控制MCU
1.采用4X4矩阵键盘实现号码输入,并在LCD液晶上显示
2.按下enter键,显示calling…,并且蜂鸣器模拟电话拨号发声
3.按下*键,退格,按下#键,清楚电话号码
4.拨号过程中,长按#取消拨号
5.采用DC002作为电源接口可直接输入5V给整个系统供电
仿真图:
主程序:文章来源:https://www.toymoban.com/news/detail-509974.html
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar keycode, DDram_value = 0xc0;
sbit rs = P2 ^ 0;
sbit rw = P2 ^ 1;
sbit e = P2 ^ 2;
sbit speaker = P2 ^ 3;
uchar speakerCnt = 0;
uchar code table[] = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x20};
uchar code table_designer[] = "Calling........";
void lcd_delay();
void delay(uint n);
void lcd_init(void);
void lcd_busy(void);
void lcd_wr_con(uchar c);
void lcd_wr_data(uchar d);
uchar checkkey(void);
uchar keyscan(void);
void main()
{
uchar num;
lcd_init();
while (1)
{
keycode = keyscan();
if ((keycode >= 0) && (keycode <= 9))
{
lcd_wr_con(0x06);
lcd_wr_con(DDram_value);
lcd_wr_data(table[keycode]);
DDram_value++;
}
else if (keycode == 0x0a)
{
lcd_wr_con(0x04);
DDram_value--;
if (DDram_value <= 0xc0)
{
DDram_value = 0xc0;
}
else if (DDram_value >= 0xcf)
{
DDram_value = 0xcf;
}
lcd_wr_con(DDram_value);
lcd_wr_data(table[10]);
}
else if (keycode == 0x0b)
{
lcd_wr_con(0x01); //清屏
DDram_value = 0xc0;
speakerCnt = 0;
}
else if (keycode == 0x0c)
{
uchar sound;
lcd_wr_con(0x06);
lcd_wr_con(0x80);
for (num = 0; num <= 14; num++)
{
lcd_wr_data(table_designer[num]);
}
speakerCnt = 50;
}
if (speakerCnt >= 1)
{
speaker = 0; //发出按键响声
delay(2000);
speaker = 1;
delay(2000);
speakerCnt--;
}
}
}
void lcd_delay() //液晶屏显示延时函数
{
uchar y;
for (y = 0; y < 0xff; y++)
{
;
}
}
void lcd_init(void) //液晶屏初始化函数,向液晶写入各种命令
{
lcd_wr_con(0x01); //清屏
lcd_wr_con(0x38); //两行显示,5×7点阵,8位数据接口
lcd_wr_con(0x0c); //开整体显示,光标关,无闪烁
lcd_wr_con(0x06); //
}
void lcd_busy(void) //判断液晶显示器是否忙的函数
{
P0 = 0xff;
rs = 0;
rw = 1;
e = 1;
e = 0;
while (P0 & 0x80)
{
e = 0;
e = 1;
}
lcd_delay();
}
void lcd_wr_con(uchar c) //向液晶显示器写命令
{
lcd_busy();
e = 0;
rs = 0;
rw = 0;
e = 1;
P0 = c;
e = 0;
lcd_delay();
}
void lcd_wr_data(uchar d) //向液晶显示器写数据
{
lcd_busy();
e = 0;
rs = 1;
rw = 0;
e = 1;
P0 = d;
e = 0;
lcd_delay();
}
void delay(uint n) //延时函数
{
uchar i;
uint j;
for (i = 50; i > 0; i--)
for (j = n; j > 0; j--)
;
}
uchar checkkey(void) //检测是否有按键按下
{
uchar temp;
P1 = 0xf0; //P1口低4位为低电平
temp = P1; //读入P1口的电平
temp = temp & 0xf0; //读入P1口的8位状态,并判断两次状态是否相同
if (temp == 0xf0) //如果P1口两次状态相同,则无键按下
{
return (0); //函数返回值为0
}
else
{
return (1); //有键按下,函数返回值为1
}
}
uchar keyscan(void) //键盘扫描并返回所按下的键号函数
{
uchar hanghao, liehao, keyvalue, buff;
if (checkkey() == 0) //如果函数返回值为0,无键按下
{
return (0xff); //返回0xff
}
仿真演示视频:
https://www.bilibili.com/video/BV1Y841187pU/文章来源地址https://www.toymoban.com/news/detail-509974.html
到了这里,关于基于51单片机的手机电话拨号盘模拟proteus仿真的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!