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

📄 main.lst

📁 用单片机控制触摸屏
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V7.50   MAIN                                                                  10/10/2008 18:23:29 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE main.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1           #include<reg51.h>
   2          /**************************************************************************************/
   3          /*工程名称:final.Uv2*/
   4          /*文件名称:main.c*/
   5          /*机构名称:大连民族学院创新教育中心电子设计部(公司/单位/学校)*/
   6          /*模块名:MAIN函数程序*/
   7          /*创建人:韦作凯 日期:2008-6-1*/
   8          /*修改人:韦作凯 日期:2008-6-7*/
   9          /*功能描述:定义全局变量、数组、调用初始化函数、功能函数*/
  10                     /*实现在线画图、计算器功能*/ 
  11          /*其他说明:能把坐标发到超级终端上去,没有上位机程序*/
  12          /*版本:V1.0版*/
  13          /**************************************************************************************/
  14           #include <stdio.h>
  15           #include <intrins.h>
  16           #define uchar unsigned char
  17           #define uint unsigned int
  18          
  19           uchar code word[10]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39} ;
  20           uchar temp_f[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00} ;
  21          
  22           /*-------------------------------函数声明---------------------------------*/
  23           
  24           /*液晶程序声明*/
  25           void write_word ( uchar word ) ;
  26           void check_busy ( void ) ;
  27           void write_command ( uchar command ) ;
  28           uchar read_word ( void ) ;
  29           void init_lcd ( void ) ;
  30           void display_word ( uchar address , uchar *list , uchar a ) ;
  31           void write_GDRAM ( uchar x , uchar y , uchar dat1 , uchar dat2 ) ;
  32           void clr_DDRAM (void) ;
  33           void clr_GDRAM ( void ) ;
  34           void drawn_point ( uchar x , uchar y ) ;
  35           void display_value ( int x , uchar addr ) ;
  36           void Read_ADS7843() ;
  37           void start() ; //SPI开始
  38           WriteCharTo7843(unsigned char num) ; //SPI写数据
  39           unsigned int ReadFromCharFrom7843 ( void ) ; //SPI 读数据
  40          
  41           /*--------------------------------接口连接---------------------------------*/
  42           
  43           /*液晶接口*/
  44           sbit lcd_rs = P1^0 ;
  45           sbit lcd_rw = P1^1 ;
  46           sbit lcd_e = P1^2 ;
  47          
  48           //按键定义 
  49          
  50           sbit key_A = P1^4 ;  //清屏
  51           sbit key_B = P1^5 ;
  52           sbit key_C = P1^3 ;
  53           sbit key_D = P1^6 ;
  54          
  55           #define lcd_db  P2 
C51 COMPILER V7.50   MAIN                                                                  10/10/2008 18:23:29 PAGE 2   

  56          
  57           //ADS7843控制口定义
  58           sbit DCLK = P3^7 ;  //根据用户自己的定义
  59           sbit CS = P3^6 ;
  60           sbit DIN = P3^5 ;
  61           sbit BUSY = P3^4 ;
  62           sbit DOUT = P3^3 ;
  63           sbit PENIR = P3^2 ; //   clear 0 when tounch else set 1
  64           unsigned int X=0,Y=0 ;
  65          
  66           /*--------------------------------变量声明---------------------------------*/
  67           int d_x ;
  68           int d_y ;
  69           int flag = 0 ;
  70           int key_flag = 0 ;
  71           int key_value = 0 ;
  72           int value_pas = 0 ;
  73           int value_act = 0 ;
  74           int value ;
  75           int value_flag = 0 ;
  76           int operator = 0 ; 
  77          
  78           /*延时*/
  79           void delay ( uint i )
  80           {
  81   1        while ( i-- );
  82   1       }
  83          
  84           /*--------------------------------按键扫描---------------------------------*/
  85           void scan_key ( void )
  86           {
  87   1          if ( key_A==0 )
  88   1                 flag = 0 ;
  89   1              if ( key_B==0 )
  90   1              {
  91   2                 flag = 1 ;
  92   2                 clr_DDRAM () ;
  93   2          }
  94   1              if ( key_C==0 )
  95   1                 flag = 2 ;
  96   1       }
  97          
  98           void check_busy ( void )
  99           {
 100   1          uchar busy ;
 101   1              lcd_db = 0xff ;
 102   1              lcd_rs = 0 ;
 103   1              lcd_rw = 1 ;
 104   1              do
 105   1              {
 106   2                 lcd_e = 1 ;
 107   2                 busy = lcd_db ;
 108   2                 delay (2) ;
 109   2                 lcd_e = 0 ;
 110   2              }while( busy>0x7f ) ;
 111   1       }
 112           
 113           /*--------------------------------------------------------------------------*/
 114          
 115           /*                                 液晶程序                                 */
 116           
 117           /*--------------------------------------------------------------------------*/
C51 COMPILER V7.50   MAIN                                                                  10/10/2008 18:23:29 PAGE 3   

 118           
 119           /*********************************液晶写命令*****************************/
 120           void write_command ( uchar command )
 121           {
 122   1          check_busy () ;
 123   1              lcd_db = command ;
 124   1          lcd_rs = 0 ;
 125   1              lcd_rw = 0 ;
 126   1              lcd_e = 1 ;
 127   1          delay (100) ;
 128   1              lcd_e = 0 ;
 129   1              //delay (100) ;
 130   1       }
 131          
 132           /**********************************液晶写数据****************************/
 133           void write_word ( uchar word)
 134           {
 135   1          check_busy () ;
 136   1              lcd_db = word ;
 137   1              lcd_rs = 1 ;
 138   1              lcd_rw = 0 ;
 139   1              lcd_e = 1 ;
 140   1          delay (100) ;
 141   1              lcd_e = 0 ;
 142   1              //delay (100) ;
 143   1       }
 144          
 145           /*************************************液晶读数据**************************/
 146           uchar read_word ( void )
 147           {
 148   1          uchar temp ;
 149   1          check_busy () ;
 150   1              lcd_db = 0xff ;
 151   1              lcd_rs = 1 ;
 152   1              lcd_rw = 1 ;
 153   1              lcd_e = 1 ;
 154   1              temp = lcd_db ;
 155   1          delay (10) ;
 156   1              lcd_e = 0 ;
 157   1              return ( temp ) ;
 158   1              //delay (100) ;
 159   1       }
 160          
 161           /*******************************液晶程序初使化****************************/
 162           void init_lcd ( void )
 163           {
 164   1          delay (1) ;
 165   1          write_command ( 0x30 ) ;  /*设置功能*/
 166   1          write_command ( 0x01 ) ;  /*开显示*/
 167   1          delay (100) ;
 168   1          write_command ( 0x06 ) ;  /*清屏*/
 169   1          write_command ( 0x0c ) ;  /*设置模式*/
 170   1       }
 171          
 172           /***********************************清GDRAM*******************************/
 173           void clr_GDRAM ( void )
 174           {
 175   1          uchar i,j;
 176   1              uchar dx,dy;
 177   1              for ( i=0;i<32;i++ )
 178   1              {
 179   2                 for ( j=0;j<16;j++)
C51 COMPILER V7.50   MAIN                                                                  10/10/2008 18:23:29 PAGE 4   

 180   2                 {
 181   3                    dy = 0x80 + i ;
 182   3                        dx = 0x80 + j ;
 183   3                        write_GDRAM ( dx,dy,0x00,0x00 ) ;
 184   3                 }
 185   2              }
 186   1          write_command ( 0x36 ) ;
 187   1      }
 188          
 189           /**********************************清DDRAM*********************************/
 190           void clr_DDRAM (void)
 191           {
 192   1          write_command ( 0x30 ) ;
 193   1          write_command ( 0x01 ) ;     //清除显示指令。
 194   1          delay (180);
 195   1       }
 196          
 197           /*********************************液晶GDRAM写数据*************************/
 198           void write_GDRAM ( uchar x , uchar y , uchar dat1 , uchar dat2 )
 199           {
 200   1              write_command ( 0x34 ) ;
 201   1              write_command ( y ) ;
 202   1              write_command ( x ) ;
 203   1              write_command ( 0x30 ) ;
 204   1              write_word ( dat1 ) ;
 205   1              write_word ( dat2 ) ;
 206   1       }
 207          
 208           /*******************************显示字符串********************************/
 209           void display_word ( uchar address , uchar *list , uchar a )
 210           {
 211   1          uchar i,j ;
 212   1              write_command ( 0x30 ) ;
 213   1          write_command (address) ;
 214   1          for( i=0;i<2*a;i++ )
 215   1          {
 216   2             j = *list ;
 217   2             write_word (j) ;
 218   2             list++ ;
 219   2          }
 220   1       }
 221          
 222           /********************************显示点***********************************/
 223           void drawn_point ( uchar x , uchar y )
 224           {
 225   1          uchar dx , dy ;
 226   1              uchar dat1 , dat2 ;
 227   1              dy = 63-y ;
 228   1              dx = x ;
 229   1              if ( dy > 31 )
 230   1              {
 231   2                 dy = dy - 32 ;
 232   2                 dx = dx + 128 ;
 233   2              }
 234   1              write_command ( 0x34 ) ;
 235   1              write_command ( dy|0x80 ) ;
 236   1              write_command ( (dx/16)|0x80 ) ;
 237   1              write_command ( 0x30 ) ;
 238   1              dat1 = read_word () ;
 239   1              dat1 = read_word () ;
 240   1              dat2 = read_word () ;
 241   1              if ( (dx%16)>7 )

⌨️ 快捷键说明

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