標(biāo)題: 關(guān)于單片機(jī)開發(fā)板點(diǎn)陣動(dòng)畫用定時(shí)器顯示有閃爍的問題 [打印本頁]

作者: zhsyc    時(shí)間: 2022-1-16 23:21
標(biāo)題: 關(guān)于單片機(jī)開發(fā)板點(diǎn)陣動(dòng)畫用定時(shí)器顯示有閃爍的問題
我抄了uid:164602大俠的一個(gè)ES2.0開發(fā)板點(diǎn)陣動(dòng)畫,我將他改成用定時(shí)器顯示后,畫面有嚴(yán)重的閃爍及重影,請(qǐng)高手幫我看看,我的代碼哪里有問題?

普中科技ES2.0單片機(jī)源程序如下:
#include<reg51.h>
#include<intrins.h>

sbit SRCLK=P3^6;
sbit RCLK=P3^5;
sbit SER=P3^4;
sbit P10=P1^0;

#define LKZ P0

unsigned char code TAB[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};

unsigned char code XS[17][8]=
{

{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*以下是箭頭向左移動(dòng)*/
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10},
{0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x38},
{0x00,0x00,0x00,0x00,0x00,0x10,0x38,0x38},
{0x00,0x00,0x00,0x00,0x10,0x38,0x38,0x54},
{0x00,0x00,0x00,0x10,0x38,0x38,0x54,0x10},
{0x00,0x00,0x10,0x38,0x38,0x54,0x10,0x10},
{0x00,0x10,0x38,0x38,0x54,0x10,0x10,0x10},
{0x10,0x38,0x38,0x54,0x10,0x10,0x10,0x10},
{0x38,0x38,0x54,0x10,0x10,0x10,0x10,0x00},
{0x38,0x54,0x10,0x10,0x10,0x10,0x00,0x00},
{0x54,0x10,0x10,0x10,0x10,0x00,0x00,0x00},
{0x10,0x10,0x10,0x10,0x00,0x00,0x00,0x00},
{0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x00},
{0x10,0x10,0x00,0x00,0x00,0x00,0x00,0x00},
{0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
};

unsigned int Times;        //為定時(shí)器計(jì)數(shù),初值為100,產(chǎn)生一個(gè)1s的定時(shí)
unsigned char i,j,k;

void XP74HC595(unsigned char dat)//向74H595發(fā)送一個(gè)字節(jié)的數(shù)據(jù)
                                                                //函數(shù)名必須由字母開始
{
        unsigned char a;
        SRCLK=0;
        RCLK=0;
        for(a=0;a<8;a++)
        {
                if ((dat<<a)&0x80)//從高位開始發(fā)送數(shù)據(jù)
                {
                        SER=1;
                }
                else
                {
                        SER=0;
                }
                SRCLK=1;
                _nop_();
                _nop_();
                SRCLK=0;      
        }

        RCLK=1;
        _nop_();
        _nop_();
        RCLK=0;
}
void DispConfig() {
        i=0;j=0;k=0;

}
void TimerConfig()
{
    Times = 1000;
        TMOD = 0x00; //選擇工作方式0
    TH0 = 0x18;         //設(shè)置初始值
    TL0 = 0x0fc;
    EA = 1;                         //打開總中斷
    ET0 = 1;                 //打開定時(shí)器0中斷
    TR0 = 1;                 //啟動(dòng)定時(shí)器0
}
void Proc_1S(){
//        P10=!P10;
}

void Proc_Disp_1ms(){
        LKZ=0xff;
        XP74HC595(0x00);
        XP74HC595(XS[ i][j]);[ i]
        LKZ=TAB[j];
        if (j<8) {
                j++;
        } else {
                j=0;
                if (k<50) {
                        k++;
                } else {
                        k=0;
                        if (i<17) {
                                i++;
                        } else {
                                i=0;
                        }
                }
        }
}

void Timer0() interrupt 1
{
        Times--;
                if (Times==0){
                        Times=1000;
                        Proc_1S();
                } else {
                        Proc_Disp_1ms();
           }
}

void main ()
{
        TimerConfig();
                DispConfig();

        while (1)
        {
        }
}

作者: lkc8210    時(shí)間: 2022-1-17 10:15
  1. void TimerConfig()
  2. {
  3.     Times = 1000;
  4.     TMOD = 0x01; //選擇工作方式1//<<<<<<<<<<<<<<<<<<<<<TH, TL 的值是16位定時(shí)器用的
  5.     TL0 = 0x18;         //設(shè)置初始值//<<<<<<<<<<<<<<<<<<<<TH, TL 的值掉轉(zhuǎn)了
  6.     TH0 = 0xfc;//<<<<<<<<<<<<<<<<<<<<TH, TL 的值掉轉(zhuǎn)了
  7.     EA = 1;                         //打開總中斷
  8.     ET0 = 1;                 //打開定時(shí)器0中斷
  9.     TR0 = 1;                 //啟動(dòng)定時(shí)器0
  10. }
  11. void Proc_1S() {
  12. //        P10=!P10;
  13. }

  14. void Proc_Disp_1ms() {
  15.     LKZ = 0xff;
  16. //        XP74HC595(0x00);//<<<<<<<<<<<<<<<<<<<<595無需清零
  17.     XP74HC595(XS[ i][j]);//[ i]
  18.     LKZ = TAB[j];
  19.     if (j < 7) { //<<<<<<<<<<<<<<<<<<<<小于8,下個(gè)循環(huán)就會(huì)出現(xiàn)XS[ i][8]和TAB[8]
  20.         j++;
  21.     } else {
  22.         j = 0;
  23.         if (k < 50) {
  24.             k++;
  25.         } else {
  26.             k = 0;
  27.             if (i < 16) { //<<<<<<<<<<<<<<<<<<<<小于17,下個(gè)循環(huán)就會(huì)出現(xiàn)XS[17][8]
  28.                 i++;
  29.             } else {
  30.                 i = 0;
  31.             }
  32.         }
  33.     }
  34. }

  35. void Timer0() interrupt 1
  36. {
  37.     TL0 = 0x18;         //設(shè)置初始值//<<<<<<<<<<<<<<<<<<<<工作方式1要手動(dòng)重裝
  38.     TH0 = 0xfc;//<<<<<<<<<<<<<<<<<<<<
  39.     Times--;
  40.     if (Times == 0) {
  41.         Times = 1000;
  42.         Proc_1S();
  43.     } else {
  44.         Proc_Disp_1ms();
  45.     }
  46. }
復(fù)制代碼

作者: munuc_w    時(shí)間: 2022-1-17 11:29
顯示屏刷新速度慢就有閃爍。




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1