打印
[单片机类]

【灯光控制任务书】 protues仿真+keilc51 仿真

[复制链接]
7567|11
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
本帖最后由 一路向北lm 于 2018-4-3 11:13 编辑

重要的事情说三遍: 明天就要蓝桥杯省赛了(4.1)、 明天就要蓝桥杯省赛了(4.1)、 明天就要蓝桥杯省赛了(4.1)、祝福考生们。
作为本版块的版主,不参加一下这个活动实在过意不去。什么没板子?什么没时间?什么老了?什么不想折腾了?...........哈哈都是借口,没板子可以仿真嘛,没时间可以等到周末呗,一切都不是问题。2017年4月份我参加了第八届蓝桥杯单片机组,在省赛中获得了一等奖,这次省赛的比较简单,自己比较幸运,把要求的功能都给实现了,现在还很感激那位借给我板子用的老师,你们为我们默默的指导着,使我们深夜写代码更加富有动力。对于本次出题的老师深表感谢,感谢您的付出,让我们这个版块更加活跃。
本次采用proteus来仿真蓝桥杯板卡,(有关应用的模块已在proteus画出)见图1,采用keil5来实现模块化编程。
录制了一段仿真的效果视频:(优酷还在审核,就直接放百度云了)
电路以及程序讲解:   https://pan.baidu.com/s/1c9w8VA6mtlQ6NBeWQNwbZA
仿真现象:                https://pan.baidu.com/s/1VEG32J8MPYXLOBHoKMeYxA
采用proteus仿真形式,对于蓝桥板板卡不一定适应,本人亲测,当年参赛也用该软件仿真,肯定比不了板子运行效果好,说句实话,对于开发板编程更容易,这个仿真编程比较难,还有就是这个仿真本人不知道如何来仿真串口,也是最后一天发帖,就当娱乐吧,分享东西给大家,得奖不得奖不重要,这次的时钟个人觉得换成ds1302比较好,历年的时钟都是考查ds1302的操作能力,用定时器来模拟就没什么意义,这次比较犟就没按照老师的要求来,还请老师多多管关照。






灯光控制任务书.rar

33.28 KB

仿真文件.rar

21.55 KB

相关帖子

沙发
一路向北lm|  楼主 | 2018-3-31 12:36 | 只看该作者
本帖最后由 一路向北lm 于 2018-3-31 12:56 编辑

模块化编程,包含led,数码管,按键,ds1302时钟,公共延时函数


主函数如下:
#include "reg52.h"
#include "led.h"
#include "delay.h"
#include "smg.h"
#include "ds1302.h"
#include "key.h"

extern unsigned char shi,fen,miao;
extern unsigned char yi,er,san,si,wu,liu,qi,ba;
extern bit LD7,LD8;
void main()
{
        //*******  初始化***********
       
  led_liushui();   //led 依次点亮
        led_off();       //led 依次熄灭
        smg_liushui();   //数码管依次点亮
        smg_off();       //数码管依次熄灭
        ds1302init();    //ds1302初始化
        while(1)
        {
       
            gettime();               //DS1302 获取时间
            yi=shi/10; er=shi%10;    //时间显示
                  si=fen/10;  wu=fen%10;
                  qi=miao/10; ba=miao%10;
                                          //时间提醒显示
                    if(miao%2==0)  
                                {
                                  san=10;             // - - 闪烁
                                        liu=10;      
                                }                                       
                    else
                                {
                                  san=11;            // - - 熄灭  
          liu=11;                                        
                                }                                       
                  display1(yi,er);
                  display2(san,si);
                  display3(wu,liu);
                  display4(qi,ba);                       
                        key_scan();
                        P2=0x80;  
                  if(LD7==1)
                        {     
        P0=0xbf;
        delay_ms(1);                               
                        }
                        else
                        {   
        P0=0xff;
                        }
                        if(LD8==1)
                        {     
        P0=0x7f;
                                delay_ms(1);
                        }
                        else
                        {     
        P0=0xff;
                        }
//                          P2=0x1f;
        }
}


使用特权

评论回复
板凳
一路向北lm|  楼主 | 2018-3-31 12:43 | 只看该作者
LED部分电路与proteus仿真电路以及相关代码如下。

             CT107平台LED原理图

             proteus仿真LED电路
#include "led.h"       

unsigned char led_tab1[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00};
unsigned char led_tab2[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff};

void led_liushui()
{
        unsigned char i;
        for(i=0;i<8;i++)
        {
          P2=0x80;      
    P0=led_tab1;
          P2=0x1f;
    delay_ms(500);               
        }

}
void led_off()
{
  unsigned char i;
        for(i=0;i<8;i++)
        {
          P2=0x80;      
    P0=led_tab2;
          P2=0x1f;
    delay_ms(500);               
        }
}



使用特权

评论回复
地板
一路向北lm|  楼主 | 2018-3-31 12:47 | 只看该作者
数码管部分电路与proteus仿真电路以及相关代码如下。

           CT107平台数码管模块

              proteus仿真电路


#include "smg.h"
unsigned char smg_du_tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff};
unsigned char smg_we_tab1[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff};
unsigned char smg_we_tab2[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00};
unsigned char yi,er,san,si,wu,liu,qi,ba;

void smg_liushui()
{
        unsigned char i;
  for(i=0;i<8;i++)
        {
          P2=0xc0;
          P0=smg_we_tab1;
          P2=0x1f;
          P0=0xff;
          P2=0xe0;         
    P0=0x00;
          P2=0x1f;
          P0=0x00;
                delay_ms(500);
        }
}
void smg_off()
{
   unsigned char i;
  for(i=0;i<8;i++)
        {
          P2=0xc0;
          P0=smg_we_tab2;
          P2=0x1f;
          P0=0xff;
          P2=0xe0;         
    P0=0x00;
          P2=0x1f;
          P0=0x00;
                delay_ms(500);
        }
}

void display1(unsigned char yi, unsigned char er)
{
    P2=0xc0;
          P0=0x01;
          P2=0x1f;
          P0=0xff;
          P2=0xe0;         
    P0=smg_du_tab[yi];
          P2=0x1f;
          P0=0x00;
          delay_ms(1);
       
          P2=0xc0;
          P0=0x02;
          P2=0x1f;
          P0=0xff;
          P2=0xe0;         
    P0=smg_du_tab[er];
          P2=0x1f;
          P0=0x00;
          delay_ms(1);
}

void display2(unsigned char san,unsigned char si)
{
    P2=0xc0;
          P0=0x04;
          P2=0x1f;
          P0=0xff;
          P2=0xe0;         
    P0=smg_du_tab[san];
          P2=0x1f;
          P0=0x00;
          delay_ms(1);
       
          P2=0xc0;
          P0=0x08;
          P2=0x1f;
          P0=0xff;
          P2=0xe0;         
    P0=smg_du_tab[si];
          P2=0x1f;
          P0=0x00;
          delay_ms(1);
}

void display3(unsigned char wu, unsigned char liu)
{
    P2=0xc0;
          P0=0x10;
          P2=0x1f;
          P0=0xff;
          P2=0xe0;         
    P0=smg_du_tab[wu];
          P2=0x1f;
          P0=0x00;
          delay_ms(1);
       
          P2=0xc0;
          P0=0x20;
          P2=0x1f;
          P0=0xff;
          P2=0xe0;         
    P0=smg_du_tab[liu];
          P2=0x1f;
          P0=0x00;
          delay_ms(1);
}

void display4(unsigned char qi, unsigned char ba)
{
    P2=0xc0;
          P0=0x40;
          P2=0x1f;
          P0=0xff;
          P2=0xe0;         
    P0=smg_du_tab[qi];
          P2=0x1f;
          P0=0x00;
          delay_ms(1);
       
          P2=0xc0;
          P0=0x80;
          P2=0x1f;
          P0=0xff;
          P2=0xe0;         
    P0=smg_du_tab[ba];
          P2=0x1f;
          P0=0x00;
          delay_ms(1);
}


使用特权

评论回复
5
一路向北lm|  楼主 | 2018-3-31 12:50 | 只看该作者
ds1302电路和proteus仿真电路以及相关代码

        CT107平台ds1302电路

          proteus仿真电路

#include "ds1302.h"
unsigned char shi,fen,miao;
void Write_Ds1302_Byte(unsigned char dat)
{
        unsigned char i;
        SCK = 0;
        for (i=0;i<8;i++)
        {
                if (dat & 0x01)
                {
                        SDA_SET;               
                }
                else
                {
                        SDA_CLR;               
                }                 
                SCK_SET;
                SCK_CLR;               
                dat = dat >> 1;
        }
}
unsigned char Read_Ds1302_Byte(void)
{
        unsigned char i, dat=0;       
        for (i=0;i<8;i++)
        {       
                dat = dat >> 1;
                if (SDA_R)           
                {
                        dat |= 0x80;
                }
                else
                {
                        dat &= 0x7F;
                }
                SCK_SET;
                SCK_CLR;
        }
        return dat;
}

void Ds1302_Single_Byte_Write(unsigned char addr, unsigned char dat)
{

        RST_CLR;                       
        SCK_CLR;                       
        RST_SET;                       
        addr = addr & 0xFE;         
        Write_Ds1302_Byte(addr);
        Write_Ds1302_Byte(dat);         
        RST_CLR;                               
}

unsigned char Ds1302_Single_Byte_Read(unsigned char addr)
{
        unsigned char temp;
        RST_CLR;                       
        SCK_CLR;                       
        RST_SET;       
        addr = addr | 0x01;         
        Write_Ds1302_Byte(addr);
        temp=Read_Ds1302_Byte();       
        RST_CLR;       
        SDA_CLR;
        return temp;
}
unsigned char dat_bcd(unsigned char dat)
{
unsigned char dat1,dat2;
dat1=dat/10;
dat2=dat%10;
dat=dat1*16+dat2;
return dat;
}
unsigned char bcd_dat(unsigned char dat)
{
unsigned char dat1,dat2;
dat1=dat/16;
dat2=dat%16;
dat=dat1*10+dat2;
return dat;
}
void ds1302init()
{
Ds1302_Single_Byte_Write(0x8e,0x00);
Ds1302_Single_Byte_Write(0x80,dat_bcd(00));
Ds1302_Single_Byte_Write(0x82,dat_bcd(00));
Ds1302_Single_Byte_Write(0x84,dat_bcd(00));
Ds1302_Single_Byte_Write(0x8e,0x80);
}
void gettime()
{
Ds1302_Single_Byte_Write(0x8e,0x00);
miao=bcd_dat(Ds1302_Single_Byte_Read(0x81));
fen=bcd_dat(Ds1302_Single_Byte_Read(0x83));
shi=bcd_dat(Ds1302_Single_Byte_Read(0x85));
Ds1302_Single_Byte_Write(0x8e,0x80);
}



使用特权

评论回复
6
一路向北lm|  楼主 | 2018-3-31 12:59 | 只看该作者
按键以及相关锁存器仿真

                 独立按键

               138+74hc02

              573锁存器电路

使用特权

评论回复
7
ohy3686| | 2018-4-4 10:49 | 只看该作者
观看了仿真视频,下载但蓝桥杯的板子也能正常运作。
1-按键功能没有反应,祥看代码,在main函数中把key_deal()注释掉了,但代码实现是正确的。
2-串口没有做,在工程源码中没发现串口相关的内容。
不过,Protuse真的是运用得很不错。

使用特权

评论回复
8
一路向北lm|  楼主 | 2018-5-7 17:40 | 只看该作者
ohy3686 发表于 2018-4-4 10:49
观看了仿真视频,下载但蓝桥杯的板子也能正常运作。
1-按键功能没有反应,祥看代码,在main函数中把key_dea ...

手边没有板子,也没办法,来凑凑热闹。

使用特权

评论回复
9
搁浅2019| | 2019-1-9 23:07 | 只看该作者
那个protues程序压缩包加密了,解压不开

使用特权

评论回复
10
路驹| | 2019-11-20 08:33 | 只看该作者
来学些东西

使用特权

评论回复
11
思难忘| | 2020-4-6 11:29 | 只看该作者
支持支持!!!

使用特权

评论回复
12
shirenjieyun| | 2022-10-17 19:18 | 只看该作者
好好学习天天向上

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

257

主题

3640

帖子

73

粉丝