標(biāo)題: stc51單片機(jī)做的六位密碼鎖控制54步進(jìn)電機(jī)自動開門 源程序 [打印本頁]

作者: 18741270696    時間: 2017-5-4 17:55
標(biāo)題: stc51單片機(jī)做的六位密碼鎖控制54步進(jìn)電機(jī)自動開門 源程序
新人學(xué)習(xí),stc系列的51單片機(jī)做的六位密碼鎖控制54步進(jìn)電機(jī)自動開門源程序。用的普通的開發(fā)板,希望大家多多指導(dǎo)


單片機(jī)源程序:
  1. #include"reg52.h"
  2. #include"1602.h"
  3. #include"key.h"
  4. #include"54power.h"

  5. #define uint unsigned int
  6. #define uchar unsigned char

  7. void UsartInit()                                    //串口初始化函數(shù)
  8. {
  9.         SCON=0X50;                                                           //設(shè)置為工作方式1
  10.         TMOD=0X20;                                                          //設(shè)置計(jì)數(shù)器工作方式2
  11.         PCON=0X80;                                                                //波特率加倍
  12.         TH1=0XF3;                                                                        //計(jì)數(shù)器初始值設(shè)置,波特慮4800
  13.         TL1=0XF3;
  14.         ES=1;                                                                                        //打開接收中斷
  15.         EA=1;                                                                                        //打開總中斷
  16.         TR1=1;       
  17. }

  18. void main()
  19. {
  20.         int i = 0;       
  21.         UsartInit();                                  //中斷初始化
  22.         init();                                 //1602初始化
  23.         while(n)
  24.         {
  25.                 t = 0;
  26.                 printfstart();                        //1602第一行輸出“Welcome back ! "
  27.                 printf();                             //通過串口1602顯示屏顯示輸入的六位密碼
  28.                 write_com(0x0C);                      //開顯示屏,光標(biāo)不顯示
  29.                 check();                                    //檢測輸入的六位密碼,正確燈亮
  30.                 write_com(0x0F);                      //開顯示屏,光標(biāo)顯示
  31.                 write_com(0x01);
  32.         }
  33.         while(1);
  34. }

  35. void timeint(void) interrupt 1
  36. {
  37.         TH0=0xFE;
  38.         TL0=0x0C;                     //設(shè)定時每隔0.5ms中斷一次
  39.         count++;
  40.         spcount--;
  41.         if(spcount<=0)
  42.         {
  43.                 spcount = speedlevel;
  44.                 gorun();
  45.         }
  46. //        turn = 1;
  47. //        step_index = 7;
  48. //        gorun();
  49. //                        step_index = 7;
  50. //                gorun();
  51. }

  52. void Usart() interrupt 4
  53. {
  54.         receiveData[t++] = SBUF;
  55.         RI = 0;
  56.         SBUF = receiveData[t-1];                      //將接收到的數(shù)據(jù)放入發(fā)送寄存器
  57.         while(!TI);                                   //等待數(shù)據(jù)發(fā)送完成


  58. …………限于本文篇幅 余下代碼請從51黑下載附件…………
復(fù)制代碼

全部資料下載:
門禁.rar (46.16 KB, 下載次數(shù): 30)






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