Bluetooth Module, SKKCA-21, Cytron


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Apr 2011
    Posts
    5

    Default Bluetooth Module, SKKCA-21, Cytron

    I am using SKKCA-21, a Bluetooth Module From Cytron. I have read a thread at
    http://www.microchip.com/forums/m221431.aspx

    I have a favour to ask, what is missing in my PIC Basic Pro Coding below? My question is how do I establish serial communication between a PC and a micro controller?

    I am using PIC16F77A to connect to a PC via a bluetooth module but the hyperterminal does not displays anything. Basically, the coding should transfer ASCII character 0, 1, until 9 to the PC when a push button is pressed.

    Disclaimer:
    The assembly language and C language does not perform the same function as my coding.

    Details:
    The language used is PIC Basic Pro, Compiler: MicroCode Studio Version 4.0, Assembler: Microchip/mpasm suite, MPLAB IDE v8.66, Windows 7.

    INCLUDE "modedefs.bas" ' Serial communication mode definition file
    DEFINE OSC 20 ' Oscillator speed is set to 20MHz
    TRISB = %11111111
    TRISC = %10000000 ' RC.7 => USART RX pin set to input
    PortC = 0
    SPBRG = 10 ' Baud Rate = 115200

    ' Variable definition
    ' ===================
    '
    count01 VAR BYTE ' variable to store TXREG content
    TXSTA = %00100100 ' Enable transmit and asynchronous mode
    RCSTA = %10010000 ' Enable serial port and continuous receive
    mainloop:


    IF (PortB.7 = 1) THEN
    FOR count01 = 0 TO 9

    PAUSE 2000

    TXREG = count01 + $30 ' Transmit Data

    HIGH PortD.2
    PAUSE 2000
    LOW PortD.2

    Next

    ENDIF

    GOTO mainloop

    END


    This is the coding from the microchip forum:

    LIST p=16F628a
    #include
    __config 0x2118


    X1 equ 0x30
    X2 equ 0x31
    X3 equ 0x32


    org 0x0000

    start
    goto initialize


    org h'0004' ;interrupt vector location


    retfie

    ;************************
    ;INITIALIZATION ROUTINE *
    ;************************

    initialize
    ;initialize ports and registers

    movlw 0x07
    movwf CMCON ;turn comparators off

    bcf STATUS,RP0

    gie01 bcf INTCON,GIE ;turn gie off
    btfsc INTCON,GIE
    goto gie01

    clrf PIR1 ;clear peripheral flags

    clrf PORTA ;clear all i/o registers...
    clrf PORTB

    bsf STATUS,RP0

    movlw b'00011111'
    movwf TRISA

    movlw b'00000110' ; RB1 = RX input, RB2=TX output
    movwf TRISB


    clrf INTCON

    clrf PIE1 ; no interrupt


    ;uart specific initialization
    ;txsta=Transmit STAtus and control register.

    bcf TXSTA,TX9 ; <6> 0 select 8 bit mode
    bsf TXSTA,TXEN ; <5> 1 enable transmit function

    bcf TXSTA,SYNC ; <4> 0 asynchronous mode.

    bsf TXSTA,BRGH ; <2> 0 disable high baud rate generator !!!


    xtal_freq = d'4000000' ;crystal frequency in Hertz.

    baudrate = d'115200' ;desired baudrate.


    spbrg_value = (xtal_freq/(baudrate*d'16'))-1


    movlw spbrg_value ;set baud rate generator value
    movwf SPBRG


    bcf STATUS,RP0

    ;more uart specific initialization
    ;rcsta=ReCeive STAtus and control register


    bsf RCSTA,SPEN ; 7 spen 1=rx/tx set for serial uart mode

    bcf RCSTA,RX9 ; 6 rc8/9 0=8 bit mode
    bcf RCSTA,SREN ; 5 sren 0=don't care in uart mode
    bsf RCSTA,CREN ; 4 cren 1=enable constant reception

    bcf RCSTA,FERR ; 2 ferr input framing error bit. 1=error

    bcf RCSTA,RX9D ; 0 rx9d input (9th data bit). ignore.



    movf RCREG,w ;clear uart receiver
    movf RCREG,w
    movf RCREG,w


    movlw 0
    movwf TXREG ;send out dummy character
    ; to get transmit flag valid!


    ;************************
    ; main programme *
    ;************************


    main

    loop
    btfss PORTA, 2 ;test if input device is ringing
    call ON1
    goto loop

    ON1
    movlw 'A'

    call transmitw ;send W to the UART transmitter
    bsf PORTB, 6 ;turn on RB2
    call Delay ;this waits for a while!
    bcf PORTB, 6 ;turn off RB2
    call Delay
    goto loop


    ;*************************************************
    ;* TRANSMIT Routines *
    ;*************************************************

    transmitw

    btfss PIR1,TXIF
    goto transmitw ;wait for transmitter interrupt flag

    movwf TXREG ;load data to be sent...

    return
    ;transmitted data is in W



    ;********************
    ;* Delay Routines *
    ;********************

    Delay movlw d'2'
    movwf X3
    B3 movlw d'255'
    movwf X2
    B2 movlw d'255'
    movwf X1
    B1 decfsz X1,f
    goto B1
    decfsz X2,f
    goto B2
    decfsz X3,f
    goto B3
    return

    end


    Anyone have materials for reference ? I am not proficient in assembly language.


    BTW, Cytron provided this coding in C for reference, a DIY project, PR6:

    C language:

    #include

    __CONFIG(0x3F32);

    #define seg PORTD // define 7 segment as PORTD

    unsigned char a;

    void init(void) // subroutine to initialize
    {
    // SPBRG=0x0A; // set baud rate as 115200 baud
    SPBRG=0x81; // set baud rate as 9600 baud
    BRGH=1;
    TXEN=1;
    CREN=1;
    SPEN=1;
    TRISD = 0b00000000;
    seg = 0b00000000;
    }

    void display(unsigned char c) // subrountine to display the text on the screen
    {
    while (TXIF == 0);
    TXREG = c;
    }

    unsigned char receive(void) // subrountine to receive text from PC
    {
    while (RCIF == 0);
    a = RCREG;
    return a;
    }

    void main(void)
    {
    init();

    while(1) // wait for 'ok' to be entered
    {
    a = receive();
    if (a == 'o')
    {
    a = receive();
    if (a == 'k') break;
    }
    }


    display('C'); // change the text for different display
    display('y');
    display('t');
    display('r');
    display('o');
    display('n');
    display(0x0a);
    display(0x0d);
    display('P');
    display('r');
    display('e');
    display('s');
    display('s');
    display(0x20);
    display('a');
    display('n');
    display('y');
    display(0x20);
    display('n');
    display('u');
    display('m');
    display('b');
    display('e');
    display('r');

    seg = 1;

    while(1) // wait for number and display it on 7 segment
    {
    a = receive();
    if (a=='1'||a=='2'||a=='3'||a=='4'||a=='5'||a=='6'||a =='7'||a=='8'||a=='9'||a=='0')
    {
    seg = a-0x30;
    }
    }


    }
    Last edited by arson88; - 11th April 2011 at 12:11. Reason: details..

  2. #2
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166

    Default Re: Bluetooth Module, SKKCA-21, Cytron

    arson88, For starters I don't see any receive routine in your version done with PicBasic or the MicroChip version done in assembly. I do however see there is a receive portion of code in the C version as well as some LCD display constants. I DO think you need to do some more homework on the interface requirements of the Cytron SKKCA-21 module before you start your coding. I personally don't have the time to research the specifications of the device you are trying to communicate to with the Pic. You need to do your own homework on the project. The people here are willing to help you as much as they can but if you don't know anything about the device you are trying to connect, how can you justify other people spending the time pouring over the spec's if you can't?

    Dave Purola,
    N8NTA

  3. #3
    Join Date
    Apr 2011
    Posts
    5

    Thumbs down Bluetooth Module, SKKCA-21, Cytron

    This BT module requirement is fairly simple:

    Bluesoleil, a BT software is needed to establish communication first. No communication can be made until both SKKCA-21 and PC with BT dongle is paired.

    [spoiler]http://www.cytron.com.my/usr_attachm...6.2.227.10.zip[/spoiler]

    PIC Basic Pro Coding:



    [spoiler]
    Code:
    INCLUDE "modedefs.bas"  ' Serial communication mode definition file
            DEFINE OSC 20           ' Oscillator speed is set to 20MHz
            TRISB = %11111111
            TRISC = %10000000       ' RC.7 => USART RX pin set to input
            PortC = 0
            SPBRG = 10              ' Baud Rate = 115200
              
            '    Variable definition
            '    ===================
            '
            count01     VAR BYTE    ' variable to store TXREG content    
            stop01      VAR BYTE 
            TXSTA.2 = 1             ' High speed
            TXSTA.5 = 1             ' Enable transmit 
            RCSTA.7 = 1             ' Bit 7, SPEN, Enable USART   
            RCSTA.4 = 1             ' Bit 4, CREN, Enable Continuous Receive 
            stop01 = 0
            mainloop:
             
                    
            IF (PortB.7 = 1) THEN 
            
            FOR count01 = 0 TO 9
            
            TXREG = count01 + $30             ' Transmit Data                       
            
            PAUSE 2000
            HIGH PortD.2
            PAUSE 2000
            LOW  PortD.2
            
            Next
           
            ENDIF 
              
            GOTO mainloop
            
            END
    [/spoiler]

    Someone please close this thread.......

  4. #4
    cheekangteh's Avatar
    cheekangteh Guest

    Default Re: Bluetooth Module, SKKCA-21, Cytron

    hi, can someone provide me sample coding PIC for SKKCA-21 in CCS??

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts