I might want to ask about uart for pic. Is it a function that is consider built in pic or we need to have another device to like rs232 to enhance the data transmitting of the pic. I'm quite confusing so i might need some opinions to research for my hobby kits.^^
and for my second problem, recently i bout a joystick from cytron in order to use it as an analogue input in pic18f4550. Though, i can't make it work whatever i try. It just respond on a positive value rather than negative values. My codings are as below
- CODE: SELECT_ALL_CODE
#include <18F4550.h> // PIC18F4550 HEADER FILE
#fuses XT,NOWDT,NOLVP,NOPROTECT // EXTERNAL CLOCK, NO WATCH DOG TIMER, NO LOW VOLTAGE
#device adc=10 // USE 10 BIT ADC QUANTIZATION
#use delay (clock=8M) // 4 MHZ CRYSTAL
#include <lcd.c>
/******************************************************************************/
#define Lcd_Rs PIN_D1
#define Lcd_Rw PIN_D2
#define Lcd_Data4 PIN_D4
#define Lcd_Data5 PIN_D5
#define Lcd_Data6 PIN_D6
#define Lcd_Data7 PIN_D7
void main()
{
int32 range,x,y;
lcd_init();
setup_adc(ADC_CLOCK_INTERNAL); // set internaal clock for ADC
setup_adc_ports(AN0_TO_AN2); // set port A0 and A2 as analog input
set_tris_b(0x00);
set_tris_a(0xFF);
output_b(0x00);
while(true)
{
set_adc_channel(2);
x=read_adc();
x=(x*5*255/1023)-128;
set_adc_channel(1);
y=read_adc();
y=(y*5*255/1023)+123;
printf(lcd_putc,"\fx = %d degree %%\n y= %d degree",(int)x,(int)y);
if((x>=0)&&(x<45))
{
output_high(PIN_B7);
}
if(x>=100)
{
output_high(PIN_B6); //led on
}
if(y>=100)
{
output_high(PIN_B1);
}
else if(y<28)
{
output_high(PIN_B0);
}
else
{
output_b(0x00);
}
}
}
I programmed it with two types, AND function with upper values and lower values, another one with either greater or less than. But it doesn't seems works with pic. Only the positive value greater than programming works (x>=100) and (y>=100) and i wonder why??? or does the SWPSJOY need another circuit to support it's rotary functions??
all advice are greatly welcomed.. thank you...^^