桂林电子科技大学信息科技学院嵌入式实训下.docx
- 文档编号:3429955
- 上传时间:2022-11-23
- 格式:DOCX
- 页数:11
- 大小:16.08KB
桂林电子科技大学信息科技学院嵌入式实训下.docx
《桂林电子科技大学信息科技学院嵌入式实训下.docx》由会员分享,可在线阅读,更多相关《桂林电子科技大学信息科技学院嵌入式实训下.docx(11页珍藏版)》请在冰豆网上搜索。
桂林电子科技大学信息科技学院嵌入式实训下
桂林电子科技大学信息科技学院
《嵌入式系统开发与应用》实训报告
指导教师:
韩桂明,张锟,赵志鹏
倒计时秒表
1系统设计
附录2:
程序清单
单片机:
#include
sbitsmg1=P2^7;
sbitsmg2=P2^6;
sbitled=P1^0;
sbitbeep=P3^6;
sbitkey_stat=P2^3;
sbitkey_up=P2^2;
sbitkey_clear=P2^1;
sbitkey_down=P2^0;
unsignedchartable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsignedchardisp[2]={9,9};
unsignedcharsmg_flag=0;
voiddelay(void)
{
unsignedchara,b;
for(b=173;b>0;b--)
for(a=143;a>0;a--);
}
voidsent(unsignedchartemp)
{
EA=0;
SBUF=temp;
while(!
TI);
TI=0;
EA=1;
}
voiddisplay(void)
{
if(smg_flag)
{
P0=table[disp[0]];
smg1=0;
smg2=1;
}
else
{
P0=table[disp[1]];
smg1=1;
smg2=0;
}
smg_flag=~smg_flag;
}
voidscan(void)
{
unsignedchartime_count=0;
unsignedcharkey_flag=0;
if(!
key_stat)
{
delay();
if(!
key_stat)
{
while(!
key_stat)
;
sent('s');
}
}
elseif(!
key_clear)
{
delay();
if(!
key_clear)
{
while(!
key_clear)
;
sent('p');
}
}
elseif(!
key_up)
{
delay();
if(!
key_up)
{
while(!
key_up)
;
sent('t');
}
}
elseif(!
key_down)
{
delay();
if(!
key_down)
{
while(!
key_down)
;
sent('b');
}
}
}
voidinit(void)
{
TMOD=0x21;
SCON=0x50;
TH0=0x0DC;
TL0=0x00;
TH1=0xFD;
TL1=TH1;
TR1=1;
ET0=1;
TR0=1;
ES=1;
EA=1;
smg1=1;
smg2=1;
led=1;
beep=0;
key_stat=1;
key_up=1;
key_clear=1;
key_down=1;
}
voidmain(void)
{
init();
while
(1)
{
scan();
}
}
voidtimer(void)interrupt1
{
TH0=0x0DC;
TL0=0x00;
display();
}
voidcom(void)interrupt4
{
unsignedcharrx_data=SBUF-10;
if(rx_data==0xff)
{
led=1;
beep=1;
}
elseif(rx_data==0xfe)
{
led=0;
beep=0;
}
else
{
disp[0]=rx_data%100/10;
disp[1]=rx_data%10;
}
RI=0;
}
ARM:
#include"shixun22.h"
#include"ui_shixun22.h"
#include
#include
shixun22:
:
shixun22(QWidget*parent):
QWidget(parent),
ui(newUi:
:
shixun22)
{
ui->setupUi(this);
SEC=60;
ui->Box->setValue(SEC);
sec=20;
lightOn=0;
s1=newQTimer;
s2=newQTimer;
s1->start(1000);
s2->start(100);
connect(s2,SIGNAL(timeout()),this,SLOT(readCom()));
connect(s1,SIGNAL(timeout()),this,SLOT(display()));
connect(ui->start,SIGNAL(clicked()),this,SLOT(start()));
myCom=newWin_QextSerialPort("COM3",QextSerialBase:
:
Polling);
myCom->open(QIODevice:
:
ReadWrite);
myCom->setBaudRate(BAUD9600);
myCom->setDataBits(DATA_8);
myCom->setParity(PAR_NONE);
myCom->setStopBits(STOP_1);
myCom->setFlowControl(FLOW_OFF);
myCom->setTimeout(50);
}
voidshixun22:
:
readCom()
{
QByteArraytemp=myCom->readAll();
if(temp[0]=='s')on_start_clicked();
if(temp[0]=='p')on_stop_clicked();
if(temp[0]=='t')on_add_clicked();
if(temp[0]=='b')on_sub_clicked();
}
shixun22:
:
~shixun22()
{
deleteui;
}
voidshixun22:
:
on_add_clicked()
{
chartemp[2]={0,0};
sec++;
ui->lcd->display(sec);
temp[0]=sec+10;
myCom->write(temp);
update();
}
voidshixun22:
:
on_reset_clicked()
{
sec=ui->Box->value();
ui->lcd->display(sec);
update();
}
voidshixun22:
:
on_start_clicked()
{
s1->start(1000);
}
voidshixun22:
:
on_sub_clicked()
{
chartemp[2]={0,0};
//if(sec!
=0)
sec--;
//elsesec==99;
ui->lcd->display(sec);
temp[0]=sec+10;
myCom->write(temp);
update();
}
voidshixun22:
:
on_stop_clicked()
{
s1->stop();
lightOn=0;
update();
}
voidshixun22:
:
paintEvent(QPaintEvent*)
{
QPainterpainter(this);
painter.setPen(Qt:
:
black);
if(lightOn)
{
painter.setBrush(Qt:
:
red);
}
else
{
painter.setBrush(Qt:
:
white);
}
painter.drawEllipse(300,10,25,25);
}
voidshixun22:
:
display()
{
chartemp[2]={0,0};
if(sec!
=0){
sec--;
ui->lcd->display(sec);
temp[0]=sec+10;
myCom->write(temp);
update();
}
else{
lightOn=!
lightOn;
update();
}
}
main的:
#include
#include"shixun22.h"
intmain(intargc,char*argv[])
{
QApplicationa(argc,argv);
shixun22w;
w.show();
returna.exec();
}
Shixun222.h:
#ifndefSHIXUN22_H
#defineSHIXUN22_H
#include
#include
#include
//#include"posix_qextserialport.h"
#include"win_qextserialport.h"
namespaceUi{
classshixun22;
}
classshixun22:
publicQWidget
{
Q_OBJECT
public:
explicitshixun22(QWidget*parent=0);
~shixun22();
voidpaintEvent(QPaintEvent*);
private:
Ui:
:
shixun22*ui;
intsec;
intSEC;
QTimer*s1;
QTimer*s2;
boollightOn;
Win_QextSerialPort*myCom;
privateslots:
voidon_Box_editingFinished();
voidon_lcd_overflow();
voidon_stop_clicked();
voidon_sub_clicked();
voidon_start_clicked();
voidon_reset_clicked();
voidon_add_clicked();
voidreadCom();
voiddisplay();
};
#endif//SHIXUN22_H
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 桂林 电子科技大学 信息 科技学院 嵌入式 实训下