• 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

    Device 
    18F45K22

    Declare Reminders Off
    CONFIG_REQ 0              Override Compiler's configuration settings
    Asm-
    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
    Endasm-
    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 
        OSCCON2.7 
    1                     ' then set
        OSCTUNE.6 = 1                     ' 
    PLL x4  16 4  64Mhyz Internal Osc
        CCP1CON 
    = %00000000        ' Disable CCP Module
        CM1CON0.7 = 0                    ' 
    Turn off all comparator 1
        CM2CON0.7 
    0                    ' Turn off all - comparator 2
        ADCON0 = 1                         ' 
    ADC's enabled
        ADCON1 = 0                         ' 
    Voltage references
        ADCON2 
    = %10101111          ' Clock selection, Justification 
        ANSELA = %00000011          ' 
    Set to digital inputs except RA0,RA1 as analogue
        ANSELB 
    0                          '  "
        ANSELC = 0                         '  "
        ANSELD = 0                         '  "
        
    ANSELE 0                         '
        TRISA = %11111111            ' 
    All Inputs
        TRISB 
    = %00000000            ' All Outputs
        TRISC = %11000000            ' 
    Watch out for this both RC7(RX) & RC6(TXneed to be set to 1
        TRISD 
    = %00000000            ' All Outputs
        TRISE = %00000000            ' 
    All Outputs
        PORTA 
    0                          '
        PORTB = 0                          '
        
    PORTC 0                          '
        PORTD = 0                          '
        
    PORTE 0                          '
            
    Varibles defined
    Dim Var1       
    As Byte   
    Dim Var2       
    As Byte

    DelayMS 20
      Cls

        
     DelayMS 100
     

    Again
    :
         
    Cls
         
    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

    xldaedalus-432

    Mysterious PORTB problem

    Thread Starter: xldaedalus

    I'm using Proton+ to develop firmware for a product with switches. The MCU is an 18F26K22. Most of the switches reside on PORTB. I am NOT using a...

    xldaedalus Yesterday, 23:42 Go to last post
    towlerg-21522

    Pic16f18877 oread

    Thread Starter: evoortman

    Hi, On a PIC16F18877 the OREAD command doesn't seem to work. The code is working on a PIC16F1939. Both controllers use 32MHz int osc. If i...

    towlerg Yesterday, 15:38 Go to last post
    Tim-107

    Lin bus and auto baud detection

    Thread Starter: Tim

    Lin bus looks to be a great system for an application i'm working on. One of the main things is the slave can be really simple without needing a...

    Tim Yesterday, 18:28 Go to last post