Proton BASIC Compiler - RS232 using PIC18F45K22 with EasyPic V7

  • PicŪ Basic

  • RS232 using PIC18F45K22 with EasyPic V7

    The program was written to test the PIC18F45K22 with MikroElektronika EasyPicV7 board.

    The PIC18F45K22 has an on board 16Mhz oscillator. If the 4*PLL is also switched on the PIC will run at a maximum speed of 64Mhz. The program tests the RS232 output and sends its data via the RS232 to USB on board converter at 115K to Realterm and also checks out the LCD display. It is intended to be just a quick an easy way of testing that the clock is running at 64Mhz and that data is being being sent.

    PHP Code:
    Declare Xtal 64

    Added by Fuse Configurator ****
    ; Use 
    the Fuse Configurator plug-in to change these settings


    Declare Reminders Off
    CONFIG_REQ 0              Override Compiler's configuration settings
    Config FOSC = INTIO67        ;Internal oscillator block
    Config PLLCFG = OFF           ;Oscillator used directly
    Config PRICLKEN = OFF        ;Primary clock can be disabled by software
    Config FCMEN = OFF           ;Fail-Safe Clock Monitor disabled
    Config IESO = OFF              ;Oscillator Switchover mode disabled
    Config PWRTEN = OFF        ;Power up timer disabled
    Config BOREN = SBORDIS    ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
    Config BORV = 190             ;VBOR set to 1.90 V nominal
    Config WDTEN = OFF          ;Watch dog timer is always disabled. SWDTEN has no effect.
    Config WDTPS = 32768       ;1:32768
    Config CCP2MX = PORTC1   ;CCP2 input/output is multiplexed with RC1
    Config PBADEN = OFF          ;PORTB<5:0> pins are configured as digital I/O on Reset
    Config CCP3MX = PORTE0   ;P3A/CCP3 input/output is mulitplexed with RE0
    Config HFOFST = On           ;HFINTOSC output and ready status are not delayed by the oscillator stable status
    Config T3CMX = PORTC0    ;T3CKI is on RC0
    Config P2BMX = PORTD2    ;P2B is on RD2
    Config MCLRE = EXTMCLR  ;MCLR pin enabled, RE3 input pin disabled
    Config STVREN = On          ;Stack full/underflow will cause Reset
    Config LVP = On                ;Single-Supply ICSP enabled if MCLRE is also 1
    Config XINST = OFF          ;Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
    Config Debug = OFF          ;Disabled
    Config CP0 = OFF             ;Block 0 (000800-001FFFh) not code-protected
    Config CP1 = OFF             ;Block 1 (002000-003FFFh) not code-protected
    Config CP2 = OFF             ;Block 2 (004000-005FFFh) not code-protected
    Config CP3 = OFF             ;Block 3 (006000-007FFFh) not code-protected
    Config CPB = OFF             ;Boot block (000000-0007FFh) not code-protected
    Config CPD = OFF             ;Data EEPROM not code-protected
    Config WRT0 = OFF          ;Block 0 (000800-001FFFh) not write-protected
    Config WRT1 = OFF          ;Block 1 (002000-003FFFh) not write-protected
    Config WRT2 = OFF          ;Block 2 (004000-005FFFh) not write-protected
    Config WRT3 = OFF          ;Block 3 (006000-007FFFh) not write-protected
    Config WRTC = OFF          ;Configuration registers (300000-3000FFh) not write-protected
    Config WRTB = OFF          ;Boot Block (000000-0007FFh) not write-protected
    Config WRTD = OFF         ;Data EEPROM not write-protected
    Config EBTR0 = OFF        ;Block 0 (000800-001FFFh) not protected from table reads executed in other blocks
    Config EBTR1 = OFF        ;Block 1 (002000-003FFFh) not protected from table reads executed in other blocks
    Config EBTR2 = OFF        ;Block 2 (004000-005FFFh) not protected from table reads executed in other blocks
    Config EBTR3 = OFF        ;Block 3 (006000-007FFFh) not protected from table reads executed in other blocks
    Config EBTRB = OFF        ;Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
    Declare Reminders On

    ;**** End of Fuse Configurator Settings ****
    --------------------------- Setup DEFINE's ----------------------------------
    Declare LCD_Type 0                   ' 
    Type of LCD Used is Alpha
    Declare LCD_DTPin PORTB.0      ' PORTX.0 -> LCD D4----PORTX.3 -> LCD D7
    Declare LCD_RSPin PORTB.4      ' 
    RS pin on RB4
    Declare LCD_ENPin PORTB.5      ' E pin on RB5
    Declare LCD_Lines 2 
    'Calculated Baudrate = 115108 @ Xtal 64MHz, Error = -0.08%
    RCSTA     = 144        ; Enable continuous receive
    TXSTA     = 36          ; Enable transmit, BRGH = 1
    SPBRG     = 138        ; Baud Rate Generator Low Byte Value
    SPBRGH    = 0           ; Baud Rate Generator High Byte Value
    BAUDCON.3 = 1         ; Enable the 16 bit Baud Rate Generator
    '------------------------  Port Initialization -------------------------------
        OSCCON =  %01111100         ' 
    Internal 16 Mhz Oscchoose primary osc 
    1                     ' then set
        OSCTUNE.6 = 1                     ' 
    PLL x4  16 4  64Mhyz Internal Osc
    = %00000000        ' Disable CCP Module
        CM1CON0.7 = 0                    ' 
    Turn off all comparator 1
    0                    ' Turn off all - comparator 2
        ADCON0 = 1                         ' 
    ADC's enabled
        ADCON1 = 0                         ' 
    Voltage references
    = %10101111          ' Clock selection, Justification 
        ANSELA = %00000011          ' 
    Set to digital inputs except RA0,RA1 as analogue
    0                          '  "
        ANSELC = 0                         '  "
        ANSELD = 0                         '  "
    ANSELE 0                         '
        TRISA = %11111111            ' 
    All Inputs
    = %00000000            ' All Outputs
        TRISC = %11000000            ' 
    Watch out for this both RC7(RX) & RC6(TXneed to be set to 1
    = %00000000            ' All Outputs
        TRISE = %00000000            ' 
    All Outputs
    0                          '
        PORTB = 0                          '
    PORTC 0                          '
        PORTD = 0                          '
    PORTE 0                          '
    Varibles defined
    Dim Var1       
    As Byte   
    Dim Var2       
    As Byte

    DelayMS 20

     DelayMS 100

    Print $FE,0"Sending Chars"
    DelayMS 1000
    For Var2 0 To $FF
    For Var1 41 To 90
         HRSOut  Var1
    " "  
    Next Var1
         Next Var2
    Print $FE,1" All done  "
    DelayMS 1000
        GoTo Again 
  • Recent Activity


    Valid time in NMEA sentance

    Thread Starter: SimonJA

    Is there any way to know that a GPS nmea sentence has the correct time? I use a module to keep a pic rtc accurate but have noticed that when...

    david Yesterday, 20:40 Go to last post

    I'm over the moon with joy. :-)

    Thread Starter: Les

    I just had to show you this, because I am over the moon with it. LOL I've just about finished procedures on the Proton 8-bit compiler so I am busy...

    towlerg Yesterday, 16:13 Go to last post

    GPS speed logger for RC planes.

    Thread Starter: david

    Hi All, This is a simple project to allow the logging of RC plane speeds to help determine battery, motor and prop variables. The code is crude and...

    david Yesterday, 21:01 Go to last post

    Baud rate problem

    Thread Starter: charliecoultas

    I am trying to run one of the USARTs on a 24HJ128GP502 at 115,200 bits/second. I thought I had defined the clock frequency wrong but Delayms gives...

    charliecoultas Today, 15:24 Go to last post