搜索
bottom↓
回复: 6

proteus仿真数码管失败。。。。。

[复制链接]

出0入0汤圆

发表于 2009-10-17 10:49:52 | 显示全部楼层 |阅读模式
在proteus中仿真数码管,在12m晶振时,数码管的第四个不显示,  4m晶振时,数码管都显示,但是闪烁。。。。。。
下周板子回来后,用板子实验。。。。。。
感觉程序应该没什么问题。。。。。
就是每10ms在定时中断中调用显示函数Dis();

#include <pic.h>
#include "delay.h"
unsigned char tick;
unsigned char sec;
const unsigned char num_code[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xC6};
unsigned char dis_buf[4]={1,2,3,5};
unsigned int ad_result[8];


__CONFIG( HS & WDTDIS& PWRTEN& BORDIS& UNPROTECT );

interrupt ISR()
{
        if(TMR1IF&&TMR1IE)
        {
                TMR1IF=0;
                TMR1H=(65526-83000/3)/256;
                TMR1L=(65526-83000/3)%256;//11.0592M   10.017MS
                tick++;
                if(tick>=100)
                        {
                                tick=0;
                                sec++;
                                dis_buf[2]=sec%10;
                                dis_buf[1]=(sec%100)/10;       
                                dis_buf[0]=sec/100;
                        }
                Dis();//显示
        }
}

Init_Tmr1()
{
        PEIE=1;
        TMR1IF=0;
        TMR1IE=1;
        T1CKPS1=0;
        T1CKPS0=0;
        TMR1CS=0;
        TMR1H=(65526-83000/3)/256;
        TMR1L=(65526-83000/3)%256;//11.0592M   10.017MS
        TMR1ON=1;
}
Init_Dis()
{
        TRISC0=0;
        TRISC1=0;
        TRISC2=0;
        TRISC3=0;//BIT

        TRISB=0X0;       
        PORTB=0XFF;
}
Dis()
{
        static unsigned char step=3;
        switch(step){
        case 0:
        RC0=0;
        RC1=1;
        RC2=1;
        RC3=1;
        PORTB=num_code[dis_buf[0]];
        break;

        case 1:
        RC0=1;
        RC1=0;
        RC2=1;
        RC3=1;
        PORTB=num_code[dis_buf[1]];
        break;

        case 2:
        RC0=1;
        RC1=1;
        RC2=0;
        RC3=1;
        PORTB=num_code[dis_buf[2]];
        break;
        case 3:
        RC0=1;
        RC1=1;
        RC2=1;
        RC3=0;
        PORTB=num_code[dis_buf[3]];
        break;
        default: break;
        }
        step++;
        if(step>=4)
                step=0;

}

void Ad_Init(void)
{
        ADCON1=0X80;//right ,all pin analog
    ADCS1=1; ADCS0=0;//F_OSC/32
        TRISA0=1;
        TRISA1=1;
        TRISA2=1;
        TRISA3=1;
        TRISA5=1;
        TRISE|=0X07;
    ADON=1;//AD MODULE WORK
}
unsigned int Ad_Convert(unsigned  char ch)
{
    unsigned  int ad_result;
    Ad_Init();
        if(ch<=7)
        {
                ADCON0&=~(7<<3);
            ADCON0|=ch<<3;
        }
        DelayUs(20);
    ADGO=1;
    for(ad_result=0;ad_result<1000;ad_result++)
                {
                        if(ADGO==0)
                                break;
                }
       
    DelayMs(1);
        ad_result=ADRESH&0XFF;
        ad_result=ad_result<<8;
        ad_result=ad_result+ADRESL;
        return ad_result;       
}

main()
{
unsigned char i=0;
Ad_Init();
Init_Tmr1();
Init_Dis();
GIE=1;
while(1)
        {
                for (i=0;i<8;i++)
                        ad_result=Ad_Convert(i);
        }
}

出0入0汤圆

发表于 2009-10-17 11:19:51 | 显示全部楼层
少搭几个原件试试,这软件的数码管就这样

出0入0汤圆

发表于 2009-10-17 18:27:14 | 显示全部楼层
I just looked at your ISR() and it is way too complicated. since you are enabling just the timer1 interrupt, you don't need to test which event has triggered the interrupt.

you also do NOT call another function from within the ISR(). put the dis() call in your main loop.

出0入0汤圆

 楼主| 发表于 2009-10-17 18:31:02 | 显示全部楼层
回楼上,我放在main  loop中也是这样的。。。。。。
其实,也怀疑程序有错的,但是找不出来。。。。。
下周,在板子上试试看。。。。。。。。。
另外,main  loop中还要添加很多其他任务中的,不太适合加DIS........

出0入0汤圆

发表于 2009-10-18 00:42:15 | 显示全部楼层
you should try to isolate the problem to certain modules and try to make sure that each module works before putting them together.

as to dis(), you can set up a software flag in the isr() so that every 10ms, that flag is set by the isr() and in the main loop, you run dis() which checks the flag. if that flag is up, it clears that flag and then does its thing. aka create a "software" interrupt of your own for dis() but outside of the real isr().

出0入0汤圆

发表于 2009-10-18 08:56:27 | 显示全部楼层
试过2ms调用一次,显示很正常,LZ不妨试试

出0入0汤圆

 楼主| 发表于 2009-10-23 14:38:55 | 显示全部楼层
呵呵,今天终于知道原因。。。。。。。。。
proteus不能在修改段显示时,必须禁止全部位选。。。。。。。。
实际电路中应该没有这个问题。。。。。
例如;
case 1:
RC0=1;
RC1=0;
RC2=1;
RC3=1;
PORTB=num_code[dis_buf[1]];
break;
改为:

case 1:
RC0=1;
RC1=1;
RC2=1;
RC3=1;
PORTB=num_code[dis_buf[1]];
case 1:
RC0=1;
RC1=0;
RC2=1;
RC3=1;
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-9 14:05

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表