Hello everyone,

I have a RN42 bluetooth module in HID profile that I am trying to get it working with PIC18F24J50.

I have a code in arduino that is working and basically moves the cursor.I want to do the same in Basic but it doesn't work.

Code in Arduino :

Code:
int led = 13;

void mouseAction(void);

void setup() {                
  pinMode(led, OUTPUT); 
  
  digitalWrite(led, HIGH);

  Serial.begin(115200);
 
  delay(500);

  digitalWrite(led, LOW);
}


void loop() {
    digitalWrite(led, LOW);
    mouseAction(0,0,10,0);
}


void mouseAction(int button,int x, int y,int wheel)
  {

  Serial.write(0xFD);
  Serial.write(0x05);
  Serial.write(0x02);
  Serial.write(button)
  Serial.write(x);
  Serial.write(y);
  Serial.write(wheel);
 
  delay(20);
  }
And this is the Basic code:

Code:
DEFINE LOADER_USED 1
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_BAUD 115200
DEFINE HSER_SPBRG 1 ' 115200 Bauds
DEFINE HSER_CLOERR 1
DEFINE OSC 4
SPBRG = 1
RCSTA = 010000 
TXSTA = 100100 

TRISC.0 = 0
TRISC.6 = 0
TRISC.7 = 1

LED VAR PORTC.0  
mainloop:
    
    high LED

   'TXREG = $FD
   'TXREG = $05
   'TXREG = $02
   'TXREG = 0
   'TXREG = 0
   'TXREG = 10
   'TXREG = 0
    
    Hserout [$FD]
    Hserout [$05]
    Hserout [$02]
    Hserout [0]
    Hserout [0]
    Hserout [10]
    Hserout [0]
   
   Pause 1000
   
   low LED
   Pause 1000 
   Goto mainloop
It doesn't work using 4Mhz internal oscillator and I wonder if that is problem and a 24 external oscillator will fix it or the is problem with my code?

I am a bit new to UART using Pic18 and I would appreciate anyway help.Thanks!