⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smgsy.lst

📁 郑州远博公司生产的单片机A型实验板原理图及配套试验源程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.20   SMGSY                                                                 06/14/2005 20:23:34 PAGE 1   


C51 COMPILER V7.20, COMPILATION OF MODULE SMGSY
OBJECT MODULE PLACED IN smgsy.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE smgsy.c DEBUG OBJECTEXTEND

line level    source

   1          /*======YB-51-A单片机通用实验板演示程序===========================*/
   2          /*======程序来源:远博科技  0371-6949037  13949105551  13603453895=======================*/
   3          /*======日期:2004.9.8=====================*/
   4          /*===================================================================
   5          
   6          [注]:AT89C51的晶振频率为11.0592MHz
   7          ====================================================================*/
   8          
   9          /*            ACM1602A (16x2)接线图
  10          =====================================================================
  11          连接线图:   ACM-------51     ACM-------51     ACM--------51
  12                      DB0-----P0.0     DB4-----P0.4     RS-------P1_0
  13                      DB1-----P0.1     DB5-----P0.5     RW-------P1_1
  14                      DB2-----P0.2     DB6-----P0.6     E--------P1_2
  15                      DB3-----P0.3     DB7-----P0.7     BLA------P1_3
  16                      
  17                      VLCD接1K电阻到GND
  18          
  19          ====================================================================*/
  20          
  21          #include <AT89X51.H>
  22          #include <stdio.h>
  23          #include <Intrins.h>
  24          //变量类型标识的宏定义
  25          #define Uchar unsigned char
  26          #define Uint unsigned int
  27          
  28          // 控制引脚定义,不同的连接必须修改的部分
  29          //74LS164定义
  30          #define SDA    P2_7    //74LS164 SAD
  31          #define SCK    P2_6    //74LS164 SCK
  32          #define BIT1   P2_5    //数码管位1
  33          #define BIT2   P2_4    //数码管位2
  34          #define BIT3   P2_3    //数码管位3
  35          #define BIT4   P2_2    //数码管位4
  36          #define BIT5   P2_1    //数码管位5
  37          #define BIT6   P2_0    //数码管位6
  38          
  39          //继电器、蜂鸣器、LED电源控制端定义
  40          #define LED    P0
  41          #define LEDSW  P3_3    //LED电源控制端
  42          #define BUZZ   P3_6    //蜂鸣器控制
  43          #define JDQ    P3_7    //继电器控制
  44          
  45          //24C02定义
  46          #define SCL24    P3_4    //24C02 SCL端
  47          #define SDA24    P3_5    //24C02 SDA端
  48          #define WriteDeviceAddress 0xa0 // 24c02写命令字
  49          #define ReadDviceAddress 0xa1   // 24c02读命令字
  50          
  51          // 1602连线
  52          #define RS    P1_0       //数据/命令选择
  53          #define RW    P1_1       //读/写选择
  54          #define Elcm  P1_2       //使能信号
  55          #define BLA   P1_3       //液晶显示屏背光
C51 COMPILER V7.20   SMGSY                                                                 06/14/2005 20:23:34 PAGE 2   

  56          
  57          #define DataPort P0      // 数据端口
  58          #define Busy    0x80
  59          
  60          //按键定义
  61          #define  K1 P1_4
  62          #define  K2 P1_5
  63          #define  K3 P1_6 
  64          #define  K4 P1_7
  65          #define  K5 P3_2        //INT0
  66          
  67          
  68          code char examp[]="   LCD-1602     WELCOME TO YBKJ";
  69          code char examp1[]="K1 be pressed!";
  70          code char examp2[]="K2 be pressed!";
  71          code char examp3[]="K3 be pressed!";
  72          code char examp4[]="K4 be pressed!";
  73          code char examp5[]="INT0 TEST";
  74          void WaitForEnable( void );
  75          void LcdWriteData( char dataW ) reentrant;
  76          void LcdWriteCommand( Uchar CMD,Uchar AttribC )reentrant ;
  77          void LcdReset( void ) reentrant;
  78          void DispOneChar(Uchar x,Uchar y,Uchar Wdata) reentrant  ;
  79          void ePutstr(Uchar x,Uchar y, Uchar code *ptr) reentrant;
  80          code Uchar szdm[]={0x03,0x9f,0x25,0x0d,0x99,0x49,0x41,0x1f,0x01,0x09};  //0-9共阴数字数码管代码
  81          void senddata(Uchar dd);
  82          void DelayMs(Uint number);
  83          void Read24c02(Uchar *RamAddress,Uchar RomAddress,Uchar bytes);  //23c02读程序
  84          void Write24c02(Uchar *Wdata,Uchar RomAddress,Uchar number);    //24c02写程序
  85          Uchar ledls(Uchar j);         //LED流水程序
  86          //void comminit(void);          //串口初始化程序
  87          void scomm(void) ;            //串口中断服务程序
  88          void int0test(void);          //int0服务程序
  89          void enint0(void);            //int0初始化
  90          Uchar  sedata,bzw=0;
  91          //测试主程序
  92          void main(void)
  93          {
  94   1          Uchar data1[6]={0x01,0x02,0x03,0x04,0x05,0x06};
  95   1              Uchar data2[6]={0x05,0x05,0x05,0x05,0x05,0x05};
  96   1              Uchar *Pdata1=data1,Romadd=0x00,counter=6,*Pdata2=data2;
  97   1          Uchar j,k,m;
  98   1              bit bz;
  99   1          DelayMs(800);
 100   1          BLA=0;                               //打开液晶显示屏背光
 101   1          LcdReset();
 102   1          ePutstr(0,0,examp);                 // 液晶屏显示一个预定字符串
 103   1          DelayMs(800);
 104   1              SCK=0;
 105   1              //comminit();        //本条语句用来打开串口中断
 106   1              enint0();
 107   1          Write24c02(Pdata1,Romadd,counter);
 108   1          Read24c02(Pdata2,Romadd,counter);
 109   1          k=m=0;
 110   1          bz=1;
 111   1              Elcm=0;                                //关闭液晶显示屏,不加此句会影响LED显示
 112   1              LEDSW=0;                               //打开LED电源
 113   1          j=0;
 114   1              DelayMs(400);
 115   1          while(1)
 116   1          {
 117   2               if (bzw==1) {                         //bzw为串口中断标志
C51 COMPILER V7.20   SMGSY                                                                 06/14/2005 20:23:34 PAGE 3   

 118   3                             senddata(szdm[sedata]); BIT6=0; 
 119   3                                                            DelayMs(3000);
 120   3                                         bzw=0;                          } 
 121   2               while ((K1&K2&K3&K4)==0)  {                            //按键测试
 122   3                                      LEDSW=1;
 123   3                                                                      BLA=0;
 124   3                                          BUZZ=0;
 125   3                                      LcdReset();
 126   3                                                              while (K1==0)  ePutstr(1,0,examp1);
 127   3                                                                      while (K2==0)  ePutstr(1,0,examp2);
 128   3                                      while (K3==0)  ePutstr(1,0,examp3);
 129   3                                                                      while (K4==0)  ePutstr(1,0,examp4); 
 130   3                                                                      BUZZ=1;
 131   3                                                                      BLA=1;
 132   3                                                                      LcdReset();
 133   3                                                                      ePutstr(0,0,examp);
 134   3                                                                      }
 135   2           LEDSW=0;                             
 136   2               LED=ledls(k); 
 137   2           // if(bz==1)    {BUZZ=0 ;JDQ=0;}     //继电器和蜂鸣器测试
 138   2               // if(bz==0)    {BUZZ=1;JDQ=1;}
 139   2               if (j==4)                           //LED延时
 140   2               { j=0; k=k+1; bz=~bz;}
 141   2           if (k==8)   { k=0; }              //使LED重新从第一个开始轮流点亮
 142   2           if (m==50)                         //使液晶屏交替亮灭
 143   2               {m=0;BLA=~BLA;}
 144   2           senddata(szdm[data2[0]]);
 145   2               BIT1=0;
 146   2           DelayMs(10);
 147   2           BIT1=1;
 148   2           senddata(szdm[data2[1]]);
 149   2               BIT2=0;
 150   2           DelayMs(10);
 151   2           BIT2=1;
 152   2           senddata(szdm[data2[2]]);
 153   2               BIT3=0;
 154   2           DelayMs(10);
 155   2           BIT3=1;
 156   2           senddata(szdm[data2[3]]);
 157   2               BIT4=0;
 158   2           DelayMs(10);
 159   2           BIT4=1;
 160   2           senddata(szdm[data2[4]]);
 161   2               BIT5=0;
 162   2           DelayMs(10);
 163   2           BIT5=1;
 164   2           senddata(szdm[data2[5]]);
 165   2               BIT6=0;
 166   2           DelayMs(10);
 167   2           BIT6=1;
 168   2               j=j+1;
 169   2           m++;
 170   2          }
 171   1      }
 172             
 173          /*串口中断服务程序*/
 174          void scomm(void) interrupt 4 {     
 175   1                                while(!RI);
 176   1                                EA=0;
 177   1                                RI=0;
 178   1                                sedata=SBUF;     //保存数据
 179   1                                SBUF=sedata;     //转发数据
C51 COMPILER V7.20   SMGSY                                                                 06/14/2005 20:23:34 PAGE 4   

 180   1                                while (!TI);
 181   1                                TI=0;
 182   1                                EA=1;
 183   1                                bzw=1;
 184   1                                    }
 185           /*串口初始化程序*/                         
 186          /*void comminit(void)     {            
 187                                    TMOD=0x20;   //定时器1方式2定时
 188                                    TH1=0xfd;
 189                                    TL1=0xfd;   //置定时器初值,选定9600bps
 190                                    SCON=0x50;  //选择通讯方式1 (1位起始,8位数据,1位停止)
 191                                    TR1=1;      //启动定时器
 192                                                            ET1=0;
 193                                    ES=1;       //开串口中断
 194                                    EA=1;       //开中断 
 195                                   }                              */
 196          /*中断0实验*/
 197          void int0test(void) interrupt 0   {
 198   1      EA=0;    //关中断
 199   1      LEDSW=1;  //关闭LED电源
 200   1      BLA=0;    //使液晶屏背景灯亮
 201   1      JDQ=0;     //继电器吸合
 202   1      BUZZ=0;     //蜂鸣器发声
 203   1      LcdReset();
 204   1      DelayMs(300);
 205   1      ePutstr(3,0,examp5);
 206   1      DelayMs(3000);
 207   1      LcdReset();
 208   1      ePutstr(0,0,examp);
 209   1      LEDSW=0;
 210   1      EA=1;
 211   1      BUZZ=1;
 212   1      JDQ=1;
 213   1      BLA=1;
 214   1                                     }
 215          void enint0(void)          {
 216   1      EX0=1; //允许中断0
 217   1      IT0=1; //脉冲触发
 218   1      EA=1;  //开中断
 219   1                              }
 220          /*串行发送8位数据 */
 221          void senddata(Uchar dd) {
 222   1      Uchar j;
 223   1      for (j=0;j<8;j++) {
 224   2                         SDA=(bit)(dd&0x01);
 225   2                                         SCK=1;  SCK=0;
 226   2                                         dd=dd>>1;
 227   2                                         }
 228   1                                               }
 229          
 230          
 231          /*使8个LED轮流发光*/
 232          Uchar ledls(Uchar j)     
 233          {  Uchar temp;
 234   1      switch (j)      {                     
 235   2      case 0:
 236   2             temp=0xfe;
 237   2                 break;
 238   2      case 1:
 239   2             temp=0xfd;
 240   2                 break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -