找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 3611|回復(fù): 3
打印 上一主題 下一主題
收起左側(cè)

跪求大神修改下單片機(jī)程序 數(shù)碼管能顯示撥碼開關(guān)的動(dòng)作

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:254045 發(fā)表于 2017-11-28 16:39 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
要求:數(shù)碼管能顯示撥碼開關(guān)的動(dòng)作,但是我的程序只能分開控制,求修改
程序和仿真都有,求幫忙

數(shù)碼管顯示撥碼開關(guān)動(dòng)作.zip

39.52 KB, 下載次數(shù): 27

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:213173 發(fā)表于 2017-11-28 19:44 | 只看該作者
沒(méi)有看到你的程序控制什么,只是用P1口的LED和數(shù)碼管顯示撥碼開關(guān)的狀態(tài)。
回復(fù)

使用道具 舉報(bào)

板凳
ID:213173 發(fā)表于 2017-11-28 19:59 | 只看該作者
數(shù)組的數(shù)據(jù)類型設(shè)置錯(cuò)誤,temp重復(fù)定義,for循環(huán)無(wú)意義。修改好了。

#include<reg51.h>
#include<intrins.h>
/********************************************************************************************************
**                         Marcos define
*********************************************************************************************************/
#define uint  unsigned int
#define uchar unsigned char
#define MotorTabNum 5

//IO設(shè)置
sbit QH    = P3^0;         //輸出端
sbit CLK   = P3^1;  //時(shí)鐘輸入端(上升沿有效)
sbit SPL   = P3^2;  //移位控制/置入控制(低電平有效)       
//數(shù)碼管
sbit SMG1 = P2^0;                                        //數(shù)碼管第一位定義
sbit SMG2 = P2^1;                                        //數(shù)碼管第二位定義
sbit SMG3 = P2^2;                                        //數(shù)碼管第三位定義
sbit SMG4 = P2^3;                                        //數(shù)碼管第四位定義
sbit SMG5 = P2^4;                                        //數(shù)碼管第五位定義
sbit SMG6 = P2^5;                                        //數(shù)碼管第六位定義
sbit SMG7 = P2^6;                                        //數(shù)碼管第七位定義
sbit SMG8 = P2^7;                                        //數(shù)碼管第八位定義
uchar  temp = 0;

uchar  table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};           //共陽(yáng)極數(shù)碼管段值

void Display(void);
void delayms(xms);
void mDelay(unsigned int DelayTime);                //延時(shí)函數(shù)

/********************************************************************************************************
* Function Name  : read_int165
* Description    : 接收數(shù)據(jù)
* Input          : None
* Output         : None
* Return         : None
********************************************************************************************************/                     
uint read_int165(void)
{
  uchar i  = 0;
  uint read_data = 0;

  SPL           = 0;          //置數(shù),讀入并行輸入口數(shù)據(jù)        
  _nop_();
  SPL           = 1;                 //移位,并口輸入被封鎖,串行轉(zhuǎn)換開始
  _nop_();


  for(i=0;i<8;i++)        //8位數(shù)據(jù)
  {
     read_data <<= 1;
     if(QH)
         {
                 read_data|=QH;
         }
             CLK=0;           //下降沿      
             _nop_();
            CLK=1;           //上升沿      
             _nop_();
  }
  return read_data;
}
/********************************************************************************************************
* Function Name  : main
* Description    : 主函數(shù)
* Input          : None
* Output         : None
* Return         : None
********************************************************************************************************/
void main()
{
        //初始化
        //  unsigned char i;
       
//        uint  temp  = 0;
        CLK=0;
        while(1)
        {
                temp  = read_int165();
                //獲取高位,存放置temp
               
                P1=temp;  //接收到的字節(jié)顯示在P1 端口,顯示的值與撥碼開關(guān)對(duì)應(yīng)
                //        for(i=0; i<10; i++)
                Display();
       
        }
}
void Display(void)
{
        unsigned char B1,B2,B3,B4,B5,B6,B7,B8;//定義數(shù)碼管的每一位
       
        B1=temp/10000000;                //取g_MotorNum的千萬(wàn)位
        B2=temp%10000000/1000000;  //取g_MotorNum的百萬(wàn)位
        B3=temp%1000000/100000;            //取g_MotorNum的十萬(wàn)位       
        B4=temp%100000/10000;                    //取g_MotorNum的萬(wàn)位
        B5=temp%10000/1000;                //取g_MotorNum的千位       
        B6=temp%1000/100;  //取g_MotorNum的百位       
        B7=temp%100/10;            //取g_MotorNum的十位       
        B8=temp%10;                    //取g_MotorNum的個(gè)位
       
        //顯示千萬(wàn)位
        P0=table[B1];
        SMG1=1;                                                         
    delayms(2);
    SMG1=0;
       
        //顯示百萬(wàn)位
        P0=table[B2];
        SMG2=1;                                                         
    delayms(5);
        SMG2=0;
        //顯示十萬(wàn)位
       
        P0=table[B3];
        SMG3=1;                                                         
    delayms(2);
        SMG3=0;
        //顯示萬(wàn)位
        P0=table[B4];
    SMG4=1;
    delayms(2);
    SMG4=0;
        //顯示千位
        P0=table[B5];
        SMG5=1;                                                         
    delayms(2);
    SMG5=0;
        //顯示百位
        P0=table[B6];
        SMG6=1;                                                         
    delayms(2);
        SMG6=0;
        //顯示十位
        P0=table[B7];
        SMG7=1;                                                         
    delayms(2);
        SMG7=0;
        //顯示個(gè)位
        P0=table[B8];
    SMG8=1;
    delayms(2);
    SMG8=0;
       
}
/********************************************************************************************************
* Function Name  : delayms
* Description    : 延時(shí)函數(shù)
* Input          : None
* Output         : None
* Return         : None
********************************************************************************************************/
void delayms(xms)
{
         unsigned int x,y;
         for(x=xms;x>0;x--)
                 for(y=110;y>0;y--);
}
回復(fù)

使用道具 舉報(bào)

地板
ID:254045 發(fā)表于 2017-11-28 20:40 | 只看該作者
謝謝啦,感恩。
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表