江苏开放大学单片机应用技术(专)第四次作业

微信小程序
资源下载
下载价格10

单片机应用技术课程 4次形考作业—单片机大作业

作业说明:第4次形考作业是单片机大作业报告,是“单元11单片机大作业”的学习检验。

学习指导:根据所选的任务选择学习第11单元给出的12个任务,或者综合运用课程所学内容。

完成日期

 

评语

 

得分

 

评阅时间

 

评阅教师

 

【单片机大作业要求】

请阅读“单片机大作业任务及内容”,在给出的任务中任选一个完成,也可以自定任务完成。

1.写清所选任务名称和任务内容。(10分)

2.要求给出设计原理图或Proteus制作的电路图。(60分)

3.最好能写出源程序(20分)、有Proteus仿真调试运行截图或实物拍照(10分)。

单片机大作业报告

所选任务名称

带按键的电子钟

任务内容

使用单片机实验板设计可显示时、分、秒的电子钟,并且具备闹钟设定及整点报时功能,当前运行的时间及闹钟设定时间可以通过按键修改,可以设定闹钟时间,可以显示当前温度。

 

一、设计原理图或Proteus制作的电路图

 

二、源程序

#include”reg51.h”

extern
void _nop_(void);

sbit
DS18B20=P3^3;

void
display(void);

void
treat0(void);

void
treat1(void);

void
treatds18b20(unsigned int temp);

void
keytreat(unsigned char nkey);

unsigned
char keyfind(void);

unsigned
int readtemperature(void);

unsigned
char data
dis[9],miao=55,fen=59,shi=23,nshi,nfen,mscount=20,nzcount,displaystate=0,zdbscount,key;

unsigned
int temperature,tempcounter=0;

 bit pause=0;

bit
nzk=0,nzqd=0,zdbs=0;

unsigned
char code
distab[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};

unsigned
char code temperaturetab[16]={0,6,13,19,25,31,38,44,50,56,62,69,75,81,88,94};

 

void
delay2nus(unsigned char n)

{

  while(n–)

  {

    _nop_;

    _nop_;

  }

}

 

void
resetds18b20(void)

{

   unsigned char i;

   DS18B20=0;

   delay2nus(255);

   DS18B20=1;

   delay2nus(30);

   while(DS18B20==0);

   DS18B20=1;

   delay2nus(240);

}

 

void
writeds18b20(unsigned char writedata)

{

     unsigned char  data i,j;

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

     {

      DS18B20=0;

      delay2nus(6);

        if(writedata&1)DS18B20=1;

        else            DS18B20=0;

        writedata=writedata>>1;

        delay2nus(30);

        DS18B20=1;

        delay2nus(3);

     }

}

 

unsigned
char   readds18b20(void)

{

   unsigned char  data
i,j,k,temp=0;

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

     {

       temp=temp>>1;

       DS18B20=0;

       _nop_();

       DS18B20=1;

       delay2nus(6);

       if(DS18B20==1)temp=temp|0x80;

       delay2nus(23);

       DS18B20=1;

     }

     return(temp);

}

 

unsigned
int readtemperature(void)

{

  unsigned char temp1=0,temp2=0;

  unsigned int result;

  if(DS18B20==0);

    else{

          resetds18b20();

          writeds18b20(0xcc);

          writeds18b20(0xBE);

          temp1=readds18b20();

          temp2=readds18b20();

          resetds18b20();

          writeds18b20(0xcc);

          writeds18b20(0x44);

          result=temp2*256+temp1;

        }

        return(result);

}

 

void  timer0(void)
interrupt 1

{

   TL0=0xc7;

   TH0=0x3c;

   if(nzqd==1)

    {

       nzcount++,P32=~P32;

       if(nzcount==200) P32=1,nzqd=0;

    }

   if(zdbs==1)

    {

       zdbscount++;

       if(zdbscount==15) P32=1,zdbs=0;

    }

   if(pause==0)

    {

       mscount–;

       if(mscount==0)

         {

            mscount=20;

            miao++;

            if(miao==60)

             {

                miao=0;

                fen++;

                if(fen==60)

                 {

                     fen=0;

                     shi++;

                     if(shi==24)  shi=0;

                 }

             }            


if((nzk==1)&&(shi==nshi)&&(fen==nfen)&&(miao==0))

             {

                nzqd=1;

                P32=0;

                nzcount=0;

             }

           if((fen==0)&&(miao==0))

             {

                zdbs=1;

                P32=0;

                zdbscount=0;

             }       

         }    

   }

  //keytreat(key);    

}

 

void
timer1(void) interrupt 3

{

   TL1=0x18;

   TH1=0xfc;

   tempcounter++;

   if(tempcounter==1000)
{tempcounter=0;temperature=readtemperature();}

   switch(displaystate)

   {

       case 0:treat0();

              break;

       case 1:treat1();

              break;

       case 2:treatds18b20(temperature);

              break;

       default:break;

   }

   display();  

}

 

void
main()

{

    unsigned char key;

    shi=7;

    fen=59;

    miao=58;

    nshi=8;

    nfen=10;

    mscount=20;

    TMOD=0x11;

    IE=0x8a;

    IP=0x02;

    TH1=0xfc;

    TL1=0x18;

    TH0=0x3c;

    TL0=0xb0;

    TR0=1;

    TR1=1;

    dis[8]=0x7f;

    while(1)

      {

          key=keyfind();

          keytreat(key);         

      }

}

 

void
treat0(void)

{

   dis[0]=distab[shi/10];

   dis[1]=distab[shi%10];

   dis[2]=0xbf;

   dis[3]=distab[fen/10];

   dis[4]=distab[fen%10];

   dis[5]=0xbf;

   dis[6]=distab[miao/10];

   dis[7]=distab[miao%10];

   dis[8]=(dis[8]&0x01)|0x7e;

}

 

void
treat1(void)

{

   dis[0]=distab[nshi/10];

   dis[1]=distab[nshi%10];

   dis[2]=0xbf;


dis[3]=distab[nfen/10];

   dis[4]=distab[nfen%10];

   dis[5]=0xbf;

   dis[6]=distab[0];

   dis[7]=distab[0];

   dis[8]=(dis[8]&0x01)|0xbe;

}

 

void
treatds18b20(unsigned int temp)

{

    unsigned char temp1,temp2;

    if((temp>>11)>0)

      {

        temp=temp–;

        temp=~temp;

        temp=temp&0x07ff;

        temp1=temp%16;

        temp2=temperaturetab[temp1];

        dis[5]=distab[temp2%10];

        dis[4]=distab[temp2/10];

        temp=temp>>4;

        temp1=temp/100;

        dis[1]=distab[temp1];

        temp1=temp%100;

        dis[2]=distab[temp1/10];

        dis[3]=distab[temp%10]-0x80;

        dis[0]=0xbf;

      }

    else

     {

        temp=temp&0x07ff;

        temp1=temp%16;

        temp2=temperaturetab[temp1] ;

        dis[5]=distab[temp2%10];

        dis[4]=distab[temp2/10];

        temp=temp>>4;

        temp1=temp/100;

        dis[1]=distab[temp1];

        temp1=temp%100;

        dis[2]=distab[temp1/10];

        dis[3]=distab[temp%10]-0x80;

        dis[0]=0xff;

     }

    dis[6]=0x9c;

    dis[7]=0xc6;

}

 

unsigned
char keyfind(void)

{

    unsigned char keytemp;

    P1=0xff;

    keytemp=P1;

    return(keytemp);

}

 

void
keytreat(unsigned char nkey)

{

    static unsigned char lkey=0x00;

    static unsigned int keycount=0;

    if(nkey==0xff) lkey=0x00,keycount=0;

    else {

             if(nzqd==1) {P32=1;nzqd=0;}   //lkey=nkey;

             if(nkey==lkey) {

                               keycount++;


if(keycount==50000)

                                 {

                                    keycount=0;


switch(lkey)

                                    {

                                      case
0xfb:switch(displaystate)


{

                                                   case
0:shi++;


if(shi==24) shi=0;


break;


case 1:nshi++;


if(nshi==24) nshi=0;


break;


default:break;

                                                 }


break;

                                      case
0xf7:switch(displaystate)


{


case 0:shi–;

                                                          if(shi==255)
shi=23;


break;


case 1:nshi–;


if(nshi==255) nshi=23;


break;


default:break;


}


break;

                                      case
0xef:switch(displaystate)


{


case 0:fen++;


if(fen==60) fen=0;


break;


case 1:nfen++;


if(nfen==60) nfen=0;

                                                          break;


default:break;


}


break;

                                      case
0xdf:switch(displaystate)


{


case 0:fen–;


if(fen==255) fen=59;


break;


case 1:nfen–;


if(nfen==255) nfen=59;


break;

                                                   default:break;


}


break;

                                      case
0xbf:switch(displaystate)

                                               {


case 0:miao++;


if(miao==60) miao=0;


break;

                                                   default:break;


}


break;

                                      case
0x7f:switch(displaystate)


{

                                                   case
0:miao–;


if(miao==255) miao=59;


break;


default:break;


}


break;


default:break;

                                    }

                                  }

                            }

 

                      else {

                              lkey=nkey;

                              keycount=0;

                              switch(nkey)

                              {

                                     case
0xfe:displaystate++;


if(displaystate==3) displaystate=0;


break;

                                     case
0xfd:switch(displaystate)

                                               {


case 0: pause=~pause;


break;


case 1: nzk=~nzk;

                                                          if(nzk==1)
dis[8]=dis[8]&0xfe;


else      dis[8]=dis[8]|1;


break;


default:break;


}


break;

                                     case
0xfb:switch(displaystate)


{

                                                  case 0:shi++;


if(shi==24) shi=0;


break;


case 1:nshi++;

                                                         if(nshi==24)
nshi=0;


break;


default:break;


}

                                               break;

                                     case
0xf7:switch(displaystate)

                                              {


case 0:shi–;

                                                         if(shi==255) shi=23;


break;


case 1:nshi–;


if(nshi==255) nshi=23;

                                                         break;


default:break;


}


break;

                                     case 0xef:switch(displaystate)


{


case 0:fen++;


if(fen==60) fen=0;

                                                         break;


case 1:nfen++;


if(nfen==60) nfen=0;


break;

                                                  default:break;


}


break;

                                     case
0xdf:switch(displaystate)

                                               {


case 0:fen–;


if(fen==255) fen=59;


break;

                                                  case 1:nfen–;


if(nfen==255) nfen=59;


break;


default:break;

                                               }


break;

                                    case
0xbf:switch(displaystate)

                                              {


case 0:miao++;


if(miao==60) miao=0;


break;


default:break;

                                              }


break;

                                    case
0x7f:switch(displaystate)

                                              {


case 0:miao–;

                                                         if(miao==255)
miao=59;


break;


default:break;

                                              }


break;


default:break;

                              }

                           }

       }

}

 

 void display(void)

  {

  static unsigned char location=0;

  P2=0xff;

  P3=0x0f|(location<<4);

  P2=dis[location];

  location++;

  if(location==9)location=0;

  }

 

 

 

三、Proteus仿真调试运行截图或实物拍照

点点赞赏,手留余香 给TA打赏

AI创作

课程作业辅导,有需要点击扫码加微信,有偿服务
支持多种货币
支持多种货币付款,满足您的付款需求
7天无忧退换
安心无忧购物,售后有保障
专业客服服务
百名资深客服7*24h在线服务
发货超时赔付
交易成功极速发货,专业水准保证时效性

站点公告

开放大学课程作业辅导,有需要扫码加微信

显示验证码

社交账号快速登录