个人单片机入门程序集合 。很适合刚学单片机的人。用的是keil proteus

源代码在线查看: receive.lst

软件大小: 10429 K
上传用户: yiranshamaoer
关键词: proteus keil 单片机 程序
下载地址: 免注册下载 普通下载 VIP

相关代码

				C51 COMPILER V8.02   RECEIVE                                                               08/12/2007 15:19:34 PAGE 1   
				
				
				C51 COMPILER V8.02, COMPILATION OF MODULE RECEIVE
				OBJECT MODULE PLACED IN receive.OBJ
				COMPILER INVOKED BY: D:\SOFTWARE\uv3\C51\BIN\C51.EXE receive.c BROWSE DEBUG OBJECTEXTEND
				
				line level    source
				
				   1          #include
				   2          #include
				   3          #define uint unsigned int
				   4          #define uchar unsigned char
				   5          #define lcd_bus P1
				   6          #define re_bus P0  //P3.0,1,2,3
				   7          uchar offset=0x80;
				   8                         //年月度    
				   9          uchar code hanzi[]={0x80,0x0f,0x12,0x0f,0x0a,0x1f,0x02,0x02,  
				  10                              0xf,0x9,0xf,0x9,0xf,0x9,0x11,0,  
				  11                              0x1C,0x14,0x1C,0x0,0x0,0x0,0x00,0x00};  
				  12          
				  13          // lcd
				  14          sbit rs=P2^0;
				  15          sbit rw=P2^1;
				  16          sbit e =P2^2;
				  17          
				  18          
				  19          //////////////////////////////////////////
				  20          delay(uchar d)
				  21          {
				  22   1              while(--d);
				  23   1      }
				  24          
				  25          
				  26          
				  27          
				  28          
				  29          /**********判断忙标志,返回的是一个位BF**********/
				  30          bit lcd_busy(void)
				  31          {
				  32   1              uchar bflag;     
				  33   1              rs=0;
				  34   1              rw=1;
				  35   1              _nop_();
				  36   1              e=1;
				  37   1              _nop_();
				  38   1              lcd_bus=0xff;
				  39   1              bflag=lcd_bus;
				  40   1              e=0;
				  41   1              return(bit)(bflag&0x80);    //BF=1 busy   
				  42   1      }
				  43          
				  44          
				  45          
				  46          /*********写命令,有两个参数,第一个是要写的命令控制字,
				  47          第二个是用来控制是否进行忙标志的判断。
				  48          busyflag=1:判断;为 0:不判断****************/
				  49          void lcd_wrcmd(uchar cmd)
				  50          {
				  51   1              while(lcd_busy());
				  52   1              lcd_bus=cmd;
				  53   1              rs=0;
				  54   1              rw=0;
				  55   1              _nop_();
				C51 COMPILER V8.02   RECEIVE                                                               08/12/2007 15:19:34 PAGE 2   
				
				  56   1              e=1;
				  57   1              _nop_();
				  58   1              _nop_();
				  59   1              e=0; 
				  60   1      }
				  61          
				  62          
				  63          /************向液晶片写数据***************/
				  64          void lcd_wrdata( uchar lcddata)
				  65          {
				  66   1              while(lcd_busy());
				  67   1              lcd_bus=lcddata;
				  68   1              rs=1;
				  69   1              rw=0;
				  70   1              _nop_();
				  71   1              e=1;
				  72   1              _nop_();
				  73   1              _nop_();
				  74   1              e=0;
				  75   1      }
				  76          
				  77          /****************初始化***************/
				  78          void lcd_ini(void)
				  79          {
				  80   1              lcd_wrcmd(0x38); 
				  81   1              delay(100);
				  82   1              lcd_wrcmd(0x0c);
				  83   1              delay(100);
				  84   1              lcd_wrcmd(0x06);
				  85   1              delay(100);
				  86   1              lcd_wrcmd(0x01);
				  87   1              delay(100);
				  88   1      }
				  89          //////////////////////////////////////////////
				  90          //
				  91          //    生成汉字子模函数
				  92          //    当lcd_wrdata(0);显示第一个汉字
				  93          //    当lcd_wrdata(1);显示第二个汉字
				  94          //
				  95          //////////////////////////////////////////////
				  96          lcd_h()
				  97          {
				  98   1          uchar i;
				  99   1          lcd_wrcmd(0x40);
				 100   1          for(i=0;i				 101   1      }
				 102          
				 103          void display(uchar temp)
				 104          {    unsigned char stra[3],r=0;
				 105   1           unsigned char  i;
				 106   1          
				 107   1             lcd_wrcmd(0x0c);
				 108   1             stra[0]=temp/100+'0';
				 109   1              stra[1]=temp%100/10+'0';
				 110   1             stra[2]=temp%10+'0';
				 111   1            
				 112   1               lcd_wrcmd(0x0c);
				 113   1            if(stra[0]=='0')
				 114   1                r=1;
				 115   1             
				 116   1            lcd_wrcmd(0xc2+r);
				 117   1             for(i=r;i				C51 COMPILER V8.02   RECEIVE                                                               08/12/2007 15:19:34 PAGE 3   
				
				 118   1             lcd_wrdata(stra[i]);
				 119   1                 
				 120   1                lcd_wrdata(2);
				 121   1             lcd_wrdata(0x43);
				 122   1          
				 123   1                
				 124   1      }
				 125          
				 126          
				 127          
				 128          
				 129          
				 130          
				 131          main()
				 132          {  uchar rect=20,temp,temp11,temp10,temp01,temp00,tt;  
				 133   1         lcd_bus=0xff;
				 134   1         lcd_ini();
				 135   1         re_bus=0xff;
				 136   1         lcd_h();
				 137   1        
				 138   1       while(1)
				 139   1       
				 140   1       {      
				 141   2          
				 142   2                re_bus=0xff;
				 143   2                rect=re_bus&0x0f;
				 144   2      
				 145   2               
				 146   2              
				 147   2                      
				 148   2                 
				 149   2                   if(rect>7&&rect				 150   2      
				 151   2                       {   
				 152   3                           temp10=rect&0x03;
				 153   3                               temp10				 154   3                               if(tt				 155   3                               temp01=0;
				 156   3                               tt=temp10;
				 157   3                        //  temp=temp11|temp10|temp01|temp00;
				 158   3                        // display(temp);
				 159   3                               rect=re_bus&0x0f;
				 160   3                      
				 161   3                              
				 162   3                        }     
				 163   2                          
				 164   2               
				 165   2                       
				 166   2            else  if(rect>3&&rect				 167   2      
				 168   2                       {   
				 169   3                           temp01=rect&0x03;
				 170   3                               temp01				 171   3                                 
				 172   3                       
				 173   3                              // temp=temp11|temp10|temp01|temp00;
				 174   3                       // display(temp);
				 175   3                                
				 176   3                               rect=re_bus&0x0f;
				 177   3                      
				 178   3                               
				 179   3                              
				C51 COMPILER V8.02   RECEIVE                                                               08/12/2007 15:19:34 PAGE 4   
				
				 180   3                        }     
				 181   2      
				 182   2      
				 183   2                      else  if(rect>11&&rect				 184   2                  { 
				 185   3                          
				 186   3                      temp00=rect&0x03;
				 187   3                          
				 188   3                          temp=temp11|temp10|temp01|temp00;
				 189   3                              display(temp);
				 190   3                              delay(100);
				 191   3                              rect=re_bus&0x0f;
				 192   3                              
				 193   3                      }
				 194   2                        
				 195   2                
				 196   2             
				 197   2                /* else  if(rect==0)
				 198   2      
				 199   2                       {   
				 200   2                           
				 201   2                               temp00=rect&0x03;
				 202   2                               temp=temp11|temp10|temp01|temp00;
				 203   2                               
				 204   2                               display(temp);
				 205   2                        } */ 
				 206   2      
				 207   2                
				 208   2                  
				 209   2      
				 210   2               
				 211   2                 
				 212   2      } 
				 213   1      
				 214   1              
				 215   1       }
				 216           
				 217          
				 218            
				 219          
				 220           
				
				
				MODULE INFORMATION:   STATIC OVERLAYABLE
				   CODE SIZE        =    319    ----
				   CONSTANT SIZE    =     24    ----
				   XDATA SIZE       =   ----    ----
				   PDATA SIZE       =   ----    ----
				   DATA SIZE        =      1       6
				   IDATA SIZE       =   ----    ----
				   BIT SIZE         =   ----    ----
				END OF MODULE INFORMATION.
				
				
				C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)
							

相关资源