Ps2ң�س����Ϸ������DZ�����д����ps2ң��������ʱ���ͣ�������ѧϰ֮�ã�--51��stm32,arduino,��ݮ�� ���룬
�����Լ������Լ����ԣ��ڴ˲������⡣
1��PS2�ֱ�����
PS2 �ֱ�����Ϸ����ң���ֱ���psx ϵ����Ϸ������ȫ�����dz�������֪ʲôʱ�������˴��� PS2 �ֱ������⣬�ƽ���ͨѶЭ�飬ʹ���ֱ����Խ�������������ң��ʹ�ã�����ң��������Ϥ�Ļ����ˡ�ͻ�����ص������������ֱ��Լ۱ȼ��ߡ������ḻ��������չ������Ӧ���С� PS2 �ֱ����ܣ�
PS2 ���ֱ������������������ɣ��ֱ���Ҫ�������Ͱ�����Ϣ������ͨ��Դ�������ֱ�����ʱ���ֱ����������Զ��������ӣ���δ���Գɹ���״̬�£��������̵���˸���ֱ��ϵĵ�Ҳ����˸�����Գɹ����������̵Ƴ������ֱ��ϵ�Ҳ��������ʱ������MODE������ѡ���ֱ�����ģʽ������ģʽ��ң������ģ��ֵ���̵�ģʽ��ң�˶�Ӧ�����ĸ�������ֻ���ĸ���������Ӧ�� ����������������Ƭ����������ʵ���������ֱ�֮����ͨѶ��
����������������
������ͼƬ
ͼ 1.1 �������������� DI/DAT���ź������ֱ������������ź���һ�� 8bit �Ĵ������ݣ�ͬ��������ʱ��
���½��ء��źŵĶ�ȡ��ʱ���ɸߵ��͵ı仯���������ɡ� DO/CMD���ź������������ֱ������źź� DI ���ԣ��ź���һ�� 8bit �Ĵ������ݣ�ͬ��������ʱ�ӵ��½��ء�
NC���ն˿ڣ� GND����Դ�أ� VDD��������������Դ����Դ��Χ 3~5V�� CS/SEL�������ṩ�ֱ������źš���ͨѶ�ڼ䣬���ڵ͵�ƽ�� CLK��ʱ���źţ����������������ڱ�������ͬ���� NC���ն˿ڣ� ACK�����ֱ���������Ӧ���źš����ź���ÿ�� 8bits ���ݷ��͵�����һ�����ڱ��Ͳ��� CS һֱ���ֵ͵�ƽ������ CS �źŲ����ͣ�Լ 60 ��PS ����������һ�����衣�ڱ���ʱδʹ��ACK �˿ڡ������������ֱ�����ʱ���������� CS �ߵ�ƽ��������һ�����0x01�����ֱ����ظ�����ID��0x41=ģ���̵ƣ�0x73=ģ�����ơ������ֱ����� ID ��ͬʱ������������ 0x42���������ݣ������ֱ����ͳ� 0x5A�������������������ˡ��� �� 1�������������ձ� | | | Bit0��Bit1��Bit2��Bit3��Bit4��Bit5��Bit6��Bit7�� | | | |
| | | |
| | | |
| | | | SELECT��L3��R3��START��UP��RIGHT��DOWN��LEFT | | | | L2��R2��L1��R1�������𡢨w���� | | | | PSS_RX��0x00=left��0xFF=right�� | | | | PSS_RY��0x00=up��0xFF=down�� | | | | PSS_LX��0x00=left��0xFF=right�� | | | | PSS_LY��0x00=up��0xFF=down�� |
���а������£���ӦλΪ��0��������λΪ��1�������統����SELECT��������ʱ��
Data[3]=11111110B��
����ģʽʱ������ҡ�˷���ģ��ֵ��0x00~0xFF ֮�䣬��ҡ�˰��µļ�ֵֵ L3��R3 ��
Ч�� �̵�ģʽʱ������ҡ��ģ��ֵΪ��Ч���Ƶ�����ʱ����Ӧ���� UP��RIGHT��DOWN��
LEFT�������𡢨w���������� L3��R3 ��Ч��
2��Ӳ�����ӷ�ʽ
�������� stm32ƽ� ���ӷ�ʽ 3��������Ӧ˵�� 
ģʽ����ѡ������ģʽ����������ʹ��ң�������Ŀ���С�����������а����ӿڶ��������������������Լ�DIY�������ܡ�
ģ��ֵ��ӦXY����ͼ��

PS2_4WD����С����51�棩����Դ�루���֣���
- #include "STC12C5A60S2.h"
- #include "stdio.h"
- #include "ps2.h"
- #define ON 1 //ʹ��LED
- #define OFF 0 //��ֹLED
-
- //������������
- sbit Left_motor_go=P2^1; //������ǰ��AIN2
- sbit Left_motor_back=P2^2; //����������AIN1
- sbit Right_motor_go=P2^4; //�ҵ���ǰ��BIN2
- sbit Right_motor_back=P2^3; //�ҵ�������BIN1
- sbit Left_motor_pwm=P2^0; //����������PWMA
- sbit Right_motor_pwm=P2^5; //�ҵ�������PWMB
- unsigned char pwm_val_left =0; //��������
- unsigned char pwm_val_right =0;
- //�ٶȵ��ڱ��� 0-200,0��С,200����
- unsigned char push_val_left =150; // ������ռ�ձ�push_val_left/200
- unsigned char push_val_right=150; // �ҵ���ռ�ձ�push_val_right/200
- //���������Ŷ���
- sbit FM=P2^7;
- //������������
- sbit ServoPin=P0^5;
- //������ʱ����
- int servocount=0;
- //���������Ƕ�ֵ
- int myangle = 0;
- //����RGB�߲ʵ�����
- sbit LED_R = P4^6; //LED_R����STC12C5A60S2��EA��P4^6���ܽ�
- sbit LED_G = P4^5; //LED_G����STC12C5A60S2��ALE��P4^5���ܽ�
- sbit LED_B = P4^4; //LED_B����STC12C5A60S2��PSEN��P4^4���ܽ�
- //�������ٿ���
- bit Left_PWM_ON=1;
- bit Right_PWM_ON=1;
- //ʱ��������С���ٶȣ�С��״̬��������
- unsigned char time;
- int g_carstate = 0;
- int g_ServoState = 0; //1��ҡ 2 ��ҡ
- //С���ٶȵ�λ
- int g_volume = 0;
- //С������״̬ö��
- enum{
- enSTOP = 0,
- enRUN,
- enBACK,
- enLEFT,
- enRIGHT,
- enUPLEFT,
- enUPRIGHT,
- enDOWNLEFT,
- enDOWNRIGHT,
- enSPINLEFT,
- enSPINRIGHT
- }enCarState;
- //�궨�������ٶȵ�λ
- #define enMinMin() do{\
- push_val_left =50; \
- push_val_right =50;\
- }while(0)
- #define enMin() do{\
- push_val_left =100; \
- push_val_right =100;\
- }while(0)
- #define enMidle() do{\
- push_val_left =150; \
- push_val_right =150;\
- }while(0)
- #define enMax() do{\
- push_val_left =200; \
- push_val_right =200;\
- }while(0)
-
- /**
- * Function delay
- * @author Danny
- * @date 2017.08.16
- * @brief ��ʱ����
- * @param xms����ʱʱ�䣨ms��
- * @retval void
- * @par History ��
- */
- void delay(unsigned int xms)
- {
- unsigned int i,j;
- for(i=xms;i>0;i--)
- for(j=850;j>0;j--);
- }
- /**
- * Function pwm_out_left_motor
- * @author Danny
- * @date 2017.08.16
- * @brief ���������� ,����push_val_left��ֵ�ı�����ת��,ռ�ձ�
- * @param void
- * @retval void
- * @par History ��
- */
- void pwm_out_left_motor(void)
- {
- if(Left_PWM_ON)
- {
- if(pwm_val_left<=push_val_left)
- {
- Left_motor_pwm =1;
- }
- else
- {
- Left_motor_pwm=0;
- }
- if(pwm_val_left>=200) //������200��������pwmΪ20ms��50hz
- pwm_val_left=0;
- }
- else
- {
- Left_motor_pwm=0; //��δ����PWM��PWMA=0 ������ֹͣ
- }
- }
- /**
- * Function pwm_out_right_motor
- * @author Danny
- * @date 2017.08.16
- * @brief �ҵ������� ,����pwm_val_right��ֵ�ı�����ת��,ռ�ձ�
- * @param void
- * @retval void
- * @par History ��
- */
- void pwm_out_right_motor(void)
- {
- if(Right_PWM_ON)
- {
- if(pwm_val_right<=push_val_right)
- {
- Right_motor_pwm=1;
- }
- else
- {
- Right_motor_pwm=0;
- }
- if(pwm_val_right>=200) //������200��������pwmΪ20ms��50hz
- pwm_val_right=0;
- }
- else
- {
- Right_motor_pwm=0; //��δ����PWM��PWMB=0�ҵ���ֹͣ
- }
- }
- /**
- * Function servo_appointed_detection
- * @author Danny
- * @date 2017.08.16
- * @brief ������ת��ָ���Ƕ�
- * @param[in] pos��ָ���ĽǶ�
- * @param[out] void
- * @retval void
- * @par History ��
- */
- void servo_appointed_detection(int pos)
- {
- int i = 0;
- for (i = 0; i <= 15; i++) //����PWM��������Ч��ʱ�Ա�֤��ת����Ӧ�Ƕ�
- {
- myangle = pos; //�����PWM
- delay(20);
- }
- }
- /**
- * Function run
- * @author Danny
- * @date 2017.08.16
- * @brief С��ǰ��
- * @param[in1] time :��ʱʱ��
- * @param[out] void
- * @retval void
- * @par History ��
- */
- void run(unsigned int time)
- {
- //������ǰ��
- Left_motor_go = 1; //������ǰ��ʹ��
- Left_motor_back = 0; //���������˽�ֹ
- //����ָ���ܽŵ�PWMֵ�����Ŀ�ʵ�ֿ��٣�0-200��
- // push_val_left=CarSpeed;
-
- //�ҵ���ǰ��
- Right_motor_go=1; //�ҵ���ǰ��ʹ��
- Right_motor_back=0; //�ҵ������˽�ֹ
- //����ָ���ܽŵ�PWMֵ�����Ŀ�ʵ�ֿ��٣�0-200��
- //push_val_right=CarSpeed;
- //��ʱ
- delay(time * 100);
- return;
- }
- /**
- * Function brake
- * @author Danny
- * @date 2017.08.16
- * @brief С��ɲ��
- * @param[in] time
- * @param[out] void
- * @retval void
- * @par History ��
- */
- void brake(unsigned int time)
- {
- //������ֹͣ
- Left_motor_go = 0; //������ǰ����ֹ
- Left_motor_back = 0; //���������˽�ֹ
-
- //�ҵ���ֹͣ
- Right_motor_go=0; //�ҵ���ǰ����ֹ
- Right_motor_back=0; //�ҵ������˽�ֹ
- //��ʱ
- delay(time * 100);
- return;
- }
- /**
- * Function left
- * @author Danny
- * @date 2017.08.16
- * @brief С����ת ��ת(���ֲ���,����ǰ��)
- * @param[in] time :��ʱʱ��
- * @param[out] void
- * @retval void
- * @par History ��
- */
- void left(unsigned int time)
- {
- //������ֹͣ
- Left_motor_go = 0; //������ǰ����ֹ
- Left_motor_back = 0; //���������˽�ֹ
- //����ָ���ܽŵ�PWMֵ�����Ŀ�ʵ�ֿ��٣�0-200��
- // push_val_left=0;
-
- //�ҵ���ǰ��
- Right_motor_go=1; //�ҵ���ǰ��ʹ��
- Right_motor_back=0; //�ҵ������˽�ֹ
- //����ָ���ܽŵ�PWMֵ�����Ŀ�ʵ�ֿ��٣�0-200��
- //push_val_right=CarSpeed;
- //��ʱ
- delay(time * 100);
- return;
- }
- /**
- * Function right
- * @author Danny
- * @date 2017.08.16
- * @brief С����ת ��ת(����ǰ��,���ֲ���)
- * @param[in] time:��ʱʱ��
- * @param[out] void
- * @retval void
- * @par History ��
- */
- void right(unsigned int time)
- {
- //������ǰ��
- Left_motor_go = 1; //������ǰ��ʹ��
- Left_motor_back = 0; //���������˽�ֹ
- //����ָ���ܽŵ�PWMֵ�����Ŀ�ʵ�ֿ��٣�0-20��
- //push_val_left=CarSpeed;
-
- //�ҵ���ֹͣ
- Right_motor_go=0; //�ҵ���ǰ����ֹ
- Right_motor_back=0; //�ҵ������˽�ֹ
- //����ָ���ܽŵ�PWMֵ�����Ŀ�ʵ�ֿ��٣�0-20��
- push_val_right=0;
- //��ʱ
- delay(time * 100);
- return;
- }
- /**
- * Function spin_left
- * @author Danny
- * @date 2017.08.16
- * @brief С��ԭ����ת ԭ����ת(���ֺ��ˣ�����ǰ��)
- * @param[in] time:��ʱʱ��
- * @param[out] void
- * @retval void
- * @par History ��
- */
- void spin_left(unsigned int time)
- {
- //����������
- Left_motor_go = 0; //������ǰ����ֹ
- Left_motor_back = 1; //����������ʹ��
- //����ָ���ܽŵ�PWMֵ�����Ŀ�ʵ�ֿ��٣�0-20��
- // push_val_left=CarSpeed;
-
- //�ҵ���ǰ��
- Right_motor_go=1; //�ҵ���ǰ��ʹ��
- Right_motor_back=0; //�ҵ������˽�ֹ
- //����ָ���ܽŵ�PWMֵ�����Ŀ�ʵ�ֿ��٣�0-20��
- // push_val_right=CarSpeed;
- //��ʱ
- delay(time * 100);
- return;
- }
- /**
- * Function spin_right
- * @author Danny
- * @date 2017.08.16
- * @brief С��ԭ����ת ԭ����ת(���ֺ��ˣ�����ǰ��)
- * @param[in] time:��ʱʱ��
- * @param[out] void
- * @retval void
- * @par History ��
- */
- void spin_right(unsigned int time)
- {
- //������ǰ��
- Left_motor_go = 1; //������ǰ��ʹ��
- Left_motor_back = 0; //���������˽�ֹ
- //����ָ���ܽŵ�PWMֵ�����Ŀ�ʵ�ֿ��٣�0-20��
- //push_val_left=CarSpeed;
-
- //�ҵ�������
- Right_motor_go=0; //�ҵ���ǰ����ֹ
- Right_motor_back=1; //�ҵ�������ʹ��
- //����ָ���ܽŵ�PWMֵ�����Ŀ�ʵ�ֿ��٣�0-20��
- //push_val_right=CarSpeed;
- //��ʱ
- delay(time * 100);
- return;
- }
- /**
- * Function up_right
- * @author Danny
- * @date 2017.08.16
- * @brief С�������Ϸ�ת
- * @param[in] time:��ʱʱ��
- * @param[out] void
- * @retval void
- * @par History ��
- */
- void up_right(unsigned int time) //����
- {
- Left_motor_go=1;
- Left_motor_back=0;
- // push_val_left=CarSpeed+50;
- push_val_left=18;
- Right_motor_go=1;
- Right_motor_back=0;
- //push_val_right=CarSpeed;
- push_val_right=10;
- //��ʱ
- delay(time * 100);
- return;
- }
- /**
- * Function down_right
- * @author Danny
- * @date 2017.08.16
- * @brief С�������·�ת
- * @param[in] time:��ʱʱ��
- * @param[out] void
- * @retval void
- * @par History ��
- */
- void down_right(unsigned int time) //����
- {
- Left_motor_go=0;
- Left_motor_back=1;
- //push_val_left=CarSpeed+50;
- push_val_left=18;
- Right_motor_go=0;
- Right_motor_back=1;
- //push_val_right=CarSpeed;
- push_val_right=10;
- delay(time * 100);
- return;
- }
- /**
- * Function up_left
- * @author Danny
- * @date 2017.08.16
- * @brief С�������Ϸ�ת
- * @param[in] time:��ʱʱ��
- * @param[out] void
- * @retval void
- * @par History ��
- */
- void up_left(unsigned int time)
- {
- Left_motor_go=1;
- Left_motor_back=0;
- //push_val_left=CarSpeed;
- push_val_left=10;
- Right_motor_go=1;
- Right_motor_back=0;
- // push_val_right=CarSpeed+50;
- push_val_right=18;
- delay(time * 100);
- return;
- }
- /**
- * Function down_left
- * @author Danny
- * @date 2017.08.16
- * @brief С�������·�ת
- * @param[in] time :��ʱʱ��
- * @param[out] void
- * @retval void
- * @par History ��
- */
- void down_left(unsigned int time)
- {
- Left_motor_go=0;
- Left_motor_back=1;
- //push_val_left=CarSpeed;
- push_val_left=10;
- Right_motor_go=0;
- Right_motor_back=1;
- //push_val_right=CarSpeed+50;
- push_val_right=18;
- delay(time * 100);
- return;
- }
- /**
- * Function back
- * @author Danny
- * @date 2017.08.16
- * @brief ������
- * @param[in] time ����ʱʱ��
- * @param[out] void
- * @retval void
- * @par History ��
- */
- void back(unsigned int time)
- {
- //����������
- Left_motor_go = 0; //������ǰ����ֹ
- Left_motor_back = 1; //����������ʹ��
-
- //�ҵ�������
- Right_motor_go=0; //�ҵ���ǰ����ֹ
- Right_motor_back=1; //�ҵ�������ʹ��
- //��ʱ
- delay(time * 100);
- return;
- }
- /**
- * Function timer0
- * @author Danny
- * @date 2017.08.16
- * @brief TIMER0�жϷ����Ӻ�������PWM�źţ����ڿ��Ƶ����ٶȺͿ��ƶ�����ת��
- * @param[in] void
- * @param[out] void
- * @retval void
- * @par History ��
- */
- void timer0()interrupt 1
- {
- int PulseWidth;
- TH0=0Xff; //100us��ʱ
- TL0=0Xa4;
- servocount++;
- //������������
- PulseWidth = ((myangle*11)+500)/100 ; //Ϊ�˽�0-180��ת��Ϊ��Ӧ������ֵ
- if(servocount == PulseWidth)
- {
- ServoPin=0; //�������ӿڵ�ƽ�ø�
- }
- if(servocount == 190) //190Ϊ���յ��Ի��õ�һ������ֵ
- {
- servocount = 0;
- ServoPin=1; //�������ӿڵ�ƽ�õ�
- }
- pwm_val_left++;
- pwm_val_right++;
- pwm_out_left_motor();
- pwm_out_right_motor();
- }
- /**
- * Function TIME0_Init
- * @author Danny
- * @date 2017.08.16
- * @brief ��ʱ��0��ʼ��
- * @param[in] void
- * @param[out] void
- * @retval void
- * @par History ��
- */
- void TIME0_Init(void)
- {
- TMOD |=0X01; //��ʱ��������ʽ1
- TH0= 0Xff; //100Us��ʱ
- TL0= 0Xa4;
- TR0= 1; //����T0����
- ET0= 1; //����T0�ж�
- EA = 1; //�����ж�
- }
- /**
- * Function color_led
- * @author Danny
- * @date 2017.08.16
- * @brief ��R,G,B��ɫ�IJ�ͬ�����γ�7�ֲ�ͬ��ɫ��
- * @param[in1] Red����
- * @param[in2] Green����
- * @param[in3] Blue����
- * @retval void
- * @par History ��
- */
- void color_led(int v_iRed, int v_iGreen, int v_iBlue)
- {
- //��ɫLED
- v_iRed == ON ? (LED_R = 1): (LED_R = 0);
- //��ɫLED
- v_iGreen == ON ? (LED_G = 1): (LED_G = 0);
- //��ɫLED
- v_iBlue == ON ? (LED_B = 1): (LED_B = 0);
- }
- /**
- * Function UartInit
- * @author Danny
- * @date 2017.08.16
- * @brief ���ڳ�ʼ��
- * ��ʱ��������ʽ2��
- * ʵ�ֵ����Զ����أ������ʵļ���Ϊ��
- * (2��SMOD�η�/32)*(sysclk(��Ƭ���ڲ�ʱ��Ƶ��)/12)/(256-TH1)
- (ϵͳĬ���µ�SMOD��0��T1X12Ҳ��Ϊ0��)
- 1/32*((11059200/12)/(256-FD))=9600
- * @param[in] void
- * @retval void
- * @par History ��
- */
- void UartInit(void)
- {
- SCON|=0x50; //���пڹ����ڷ�ʽ1���������н���
- TMOD|=0x20; //��ʱ��1������ʽ2���Զ����س�ֵ��TL1����ʼֵ��TH1������ֵ
- TH1=0xfd; //��ʼ��������Ϊ9600
- TL1=0xfd;
- TI=1; //���ͱ�־λ��1����ʾ������һ���ֽ�
- TR1=1; //��ʱ��1��ʼ����
- }
- /**
- * Function PS2_control
- * @author Danny
- * @date 2017.07.25
- * @brief PS2������
- * @param[in] void
- * @param[out] void
- * @retval void
- * @par History ��
- */
- void PS2_control()
- {
- //PS2������������
- stPS2KeyValue * PS2;
-
- PS2 = ReadPS2KeyValue(); //�����ֱ�����֮�����õ�ֵ
- //��data[3]��data[4]�����������ϳ�16λ������
- //��data[4]data[3]:��select����ʱ
- //FunBtn��0x1111 1111 1111 1110
- if((PS2->FunBtn & PSB_SELECT) == 0)
- {
- printf("PSB_SELECT!\n");
- }
-
- if((PS2->FunBtn & PSB_START) == 0)
- {
- printf("PSB_START!\n");
- }
-
- if((PS2->FunBtn & PSB_L3) == 0)
- {
- printf("PSB_L3!\n");
- g_carstate = enSTOP; //��С������Ϊֹͣ״̬
- }
- if((PS2->FunBtn & PSB_R3) == 0)
- {
- printf("PSB_R3!\n");
- g_carstate = enSTOP; //��С������Ϊֹͣ״̬
- }
- if((PS2->FunBtn & PSB_PAD_UP) == 0)
- {
- printf("PSB_PAD_UP!\n");
- g_carstate = enRUN; //��С������Ϊǰ��״̬
- }
- else if((PS2->FunBtn & PSB_PAD_RIGHT) == 0)
- {
- printf("PSB_PAD_RIGHT!\n");
- g_carstate = enRIGHT; //��С������Ϊ״̬��ת
- }
- else if((PS2->FunBtn & PSB_PAD_DOWN) == 0)
- {
- printf("PSB_PAD_DOWN!\n");
- g_carstate = enBACK; //��С������Ϊ����״̬
- }
- else if((PS2->FunBtn & PSB_PAD_LEFT) == 0)
- {
- printf("PSB_PAD_LEFT!\n");
- g_carstate = enLEFT; //��С������Ϊ��ת״̬
- }
-
- else //ȥ��������һֱִ�У��Ӵ˶����ſ�ֹͣ
- {
- g_carstate = enSTOP; //��С������Ϊֹͣ״̬
- }
-
- if((PS2->FunBtn & PSB_L2) == 0) //����
- {
- printf("PSB_L2!\n");
- // CarSpeed=CarSpeed+40;
- // if(CarSpeed>=200)
- // {
- // CarSpeed = 200;
- // }
- g_volume++;
- if(g_volume>=4) //���ٶ��������ĸ��ȼ�
- {
- g_volume = 4;
- }
- }
-
- if((PS2->FunBtn & PSB_R2) == 0) //����
- {
- printf("PSB_R2!\n");
- // CarSpeed=CarSpeed-40;
- // if(CarSpeed<0)
- // {
- // CarSpeed = 50;
- // }
- g_volume--;
- if(g_volume <= 0)
- {
- g_volume = 1;
- }
- }
- //���ֱ���L1�������º�������������ҡ�����ݣ�X1��Y1��֮������
- //����ҡ�˿���С��������״̬
- if((PS2->FunBtn & PSB_L1) == 0)
- {
- printf("PSB_L1!\n");
-
- if (PS2->Y1 < 5 && PS2->X1 > 80 && PS2->X1 < 180) //��
- {
- g_carstate = enRUN;
- printf("enRUN\n");
- }
- else if (PS2->Y1 > 230 && PS2->X1 > 80 && PS2->X1 < 180) //��
- {
- g_carstate = enBACK;
- printf("enBACK\n");
- }
- else if (PS2->X1 < 5 && PS2->Y1 > 80 && PS2->Y1 < 180) //��
- {
- g_carstate = enLEFT;
- printf("enLEFT\n");
- }
- else if (PS2->Y1 > 80 && PS2->Y1 < 180 && PS2->X1 > 230)//��
- {
- g_carstate = enRIGHT;
- printf("enRIGHT\n");
- }
- else if (PS2->Y1 <= 80 && PS2->X1 <= 80) //����
- {
- g_carstate = enUPLEFT;
- printf("enUPLEFT\n");
- }
- else if (PS2->Y1 <= 80 && PS2->X1 >= 180) //����
- {
- g_carstate = enUPRIGHT;
- printf("enUPRIGHT\n");
- }
- else if (PS2->X1 <= 80 && PS2->Y1 >= 180) // ����
- {
- g_carstate = enDOWNLEFT;
- printf("enDOWNLEFT\n");
- }
- else if (PS2->Y1 >= 180 && PS2->X1 >= 180) //����
- {
- g_carstate = enDOWNRIGHT;
- printf("enDOWNRIGHT\n");
- }
- else//ͣ
- {
- g_carstate = enSTOP;
- }
- }
- //��R1������֮���������Ҳ�ҡ����������ʱ��
- //�Ҳ�ҡ�˿���С���Ķ���������״̬
- if((PS2->FunBtn & PSB_R1) == 0)
- {
- printf("PSB_R1!\n");
- //��ҡ��
- if (PS2->X2 < 5 && PS2->Y2 > 80 && PS2->Y2 < 180) //��
- {
- g_ServoState = 1;
- }
- else if (PS2->Y2 > 80 && PS2->Y2 < 180 &&PS2->X2 > 230)//��
- {
- g_ServoState = 2;
- }
- else //��λ
- {
- g_ServoState = 0;
- }
- }
-
- if((PS2->FunBtn & PSB_TRIANGLE) == 0) // ���Ƶ�
- {
- printf("PSB_TRIANGLE!\n");
- color_led(ON, OFF, ON);
- // ReadPS2KeyValue();
- }
-
- if((PS2->FunBtn & PSB_CIRCLE) == 0) // ��������
- {
- printf("PSB_CIRCLE!\n");
- g_carstate = enLEFT;
- // ReadPS2KeyValue();
- }
-
- if((PS2->FunBtn & PSB_CROSS) == 0) // ����
- {
- printf("PSB_CROSS!\n");
- FM = 0;
- delay(500);
- FM = 1;
- // ReadPS2KeyValue();
- }
-
- if((PS2->FunBtn & PSB_SQUARE) == 0) //��������
- {
- printf("PSB_SQUARE!\n");
- g_carstate = enRIGHT;
- // ReadPS2KeyValue();
- }
- }
���ƴ��� ȫ������51hei���ص�ַ��
|