这个模块是干什么用的。
这个模块的杜邦线口是什么用的。和单片机怎么连接
摇杆不会连接
摇杆不会连接
- #include "reg52.h" //52μ¥Ƭ»úí¨óüÄ′æÆ÷£¬è±T2MOD¶¨òå
- #include "intrins.h" //×Ö·û¿ØÖÆ£¬×óòÆ/óòòÆ£¬¿ÕÖ¸áîμè
- #include "stdio.h" //êäèë¡¢êä3ö¿ØÖÆ
- #include "string.h" //×Ö·û′®′|àí
- #include "math.h" //êyѧoˉêy
- #include "absacc.h" //ROM/RAM′|àí
- #include "hardware.h" //Ïμí3ó2¼tá¬Ïß
- #include "MACRO_AND_CONST.h" //3£óñäá¿o궨òå
- #include "LCD1602.h" //LCD1602í·Îļt
- #include "ADC12.h"
- #include "delay.h"
- uchar dis_buf[16]={0}
- uint sx=0,sy=0
- uint b[10]={0},c[10]={0}
- uint refx=0,refy=0
- uchar mode=0,i=0,j=0
- void scankey()
- {
- if(key==0)
- {
- delay_ms(10);
- if(key==0)
- {
- if(mode==1)
- mode=0
- else if(mode==0)
- mode=1
- while(key==0)
- {
- if(key==1)
- {
- delay_ms(10);
- if(key==1)
- break;
- }
- ;
- }
- }
- }
- }
- //-----------------------------------------------------------------
- void ADC()
- {
- ulong a=0;
- a=GetADCResult(0)&0x03;
- a=ADC_LOW8+a*256;//a=0-1023
- b[i]=a;
- a=GetADCResult(1)&0x03;
- a=ADC_LOW8+a*256;
- c[j]=a;
- i++;
- if(i>9)
- i=0;
- j++;
- if(j>9)
- j=0;
- }
- //-----------------------------------------------------------------
- void display_LCD(
- {
- sprintf(dis_buf,"X:%03d",sx);
- LCD_Show_String(0,0,dis_buf,1)
- sprintf(dis_buf,"Y:%03d",sy);
- LCD_Show_String(1,0,dis_buf,1)
- }
- main()
- {
- ulong x,y;
- uchar n;
- Initialize_LCD();
- InitADC();
- delay_ms(100);
- x=0;
- y=0;
- for(n=0;n<10;n++
- {
- ADC();
- delay_ms(5);
- x=x+b[n];
- y=y+c[n];
- }
- refx=x/10;
- refy=y/10;
- mode=0;
- while(1)
- {
- scankey();
- ADC();
- x=0;
- y=0;
- for(n=0;n<10;n++)
- {
- x=x+b[n];
- y=y+c[n];
- }
- if(mode==0)
- {
- sx=(x*9/512);
- sy=(y*9/512);
- }
- else if(mode==1)
- {
- if(x>=refx*10)
- sx=(x-refx*10)*9/(1024-refx)+90;
- else if(x<refx*10)
- sx=x*9/refx;
- if(y>=refy*10)
- sy=(y-refy*10)*9/(1024-refy)+90;
- else if(y<refy*10)
- sy=y*9/refy;
- }
- display_LCD();
- delay_ms(100);
- }
- }
- MACRO_AND_CONST.h里找到的
- /TLC561硬件接口
- //-------------------------------------------------
- /*
- sbit CS_5615 = P1^2;
- sbit CLK_5615 = P1^1;
- sbit DIN_5615 = P1^0;
- sbit DOUT_5615 = P1^3;
- */
复制代码 |