iamintel
Joined: 24 Nov 2009 Posts: 1
|
PS 2 controller using UART |
Posted: Wed Jan 19, 2011 2:51 pm |
|
|
Hi
I'm programming PIC16F877A to send and receive data via UART using this device I just bought from cytron
http://www.cytron.com.my/usr_attachment/SKPS%20User%20Manual.pdf please refer to the manual
but still no luck programming it.
For now, I just try to program one button (p_square) to switch LED (portb7) on/off and from the manual the host(PIC) need to send data to the device and the device return value=0(if pressed).
I did some programs, but none of them worked
Below is my code:
Code: |
#include <16f877a.h>
#use delay(clock=20000000)
#fuses hs, noprotect, nowdt, nolvp
#use rs232(baud=9600 ,xmit=PIN_C6,rcv=PIN_C7, parity=N, ERRORS)//rs232 settings
#byte porta=5
#byte portb=6
#byte portc=7
#byte portd=8
#byte porte=9
int get_data , send_data;
#define p_select 0// in decimal
#define p_joyl 1
#define p_joyr 2
#define p_start 3
#define p_up 4
#define p_right 5
#define p_down 6
#define p_left 7
#define p_l2 8
#define p_r2 9
#define p_l1 10
#define p_r1 11
#define p_triangle 12
#define p_circle 13
#define p_cross 14
#define p_square 15
#define p_joy_lx 16
#define p_joy_ly 17
#define p_joy_rx 18
#define p_joy_ry 19
#define p_joy_lu 20
#define p_joy_ld 21
#define p_joy_ll 22
#define p_joy_lr 23
#define p_joy_ru 24
#define p_joy_rd 25
#define p_joy_rl 26
#define p_joy_rr 27
//serial interrupt
#int_rda
RDA_isr()
{
if(kbhit())
{
putc(send_data);
}
get_data = getch();
}
void main()
{
// set i/o
set_tris_a(0xff);
set_tris_b(0x02);
set_tris_c(0xff);
setup_port_a(NO_ANALOGS);
setup_timer_2(T2_DIV_BY_16, 100, 1);
set_rtcc(0);
setup_counters(RTCC_INTERNAL, RTCC_DIV_1);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
//set serial interrupt
enable_interrupts(int_rda);
enable_interrupts(GLOBAL);
do
{
if(send_data =15) // press p_square button
{
if (get_data==0)
{
output_low(pin_b7); //Led Off
delay_ms(50);
}
}
else
{
output_high(pin_b7);//Led On
delay_ms(50);
}
}while(1);
}
|
Will some of you guys look at this code and help me out
Thanks |
|