Interface for 16f818


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2008
    Posts
    5

    Default Interface for 16f818

    I'm want to how to wire my 16F818 PIC up for interface my with PC and want to read to data from the PIC using VB.

    I have a max233cpp chip and also RS232 to usb convertor.

    I have set reg sspcon bit 5 to 1 on PIC for data output as thats all I need to use.

    Any help would be great thanks.

  2. #2
    Join Date
    Oct 2004
    Location
    North Norfolk UK
    Posts
    146

    Default

    Welcome
    Quote Originally Posted by davekav View Post
    Any help would be great thanks.
    Any code/details would be great thanks

    Duncan

    __________________

  3. #3
    Join Date
    Apr 2008
    Posts
    5

    Default

    This is my first PIC Project and have enjoyed it so far but having trouble moving forward at the minute.

    Details:
    The PIC is been used for a prototype alarm system for toy car and hoping to then interface with PC to give a nice GUI and display which sensor was triggered.

    Code:

    list p=16f818 ; list directive to define processor
    #include ; processor specific variable definitions

    errorlevel -302 ; suppress message 302 from list file

    __CONFIG H'3F10'

    ;***** VARIABLE DEFINITIONS
    OPTION_R EQU 81H ;Option Register
    ZEROBIT EQU 2 ;means ZEROBIT is bit 2.
    COUNT EQU 20H ;COUNT a register to count events.
    COUNTA EQU 21H

    ;************************************************* *********************
    ORG 0x000 ; processor reset vector
    goto main ; go to beginning of program


    ; SUBROUTINE SECTION.

    DELAY MOVLW 0xFF ;load Decimal FF in W register
    MOVWF COUNT ;load Count with contents of W register
    LOADCA MOVLW 0xFF ;load Decimal FF in W register
    MOVWF COUNTA ;load CountA with contents of W register
    DEC DECFSZ COUNTA,F;decrement counterA and skip next line if Z=0
    GOTO DEC ;if countA not 0 than go to DEC
    DECFSZ COUNT,F ;decrement counter1 and skip next line if Z=0
    GOTO LOADCA ;if count1 not 0 than go to LOADC2
    RETURN ;else jump out of subroutine


    ;FLASH LEDS
    LED BSF PORTA,0 ;Turn on A0
    BSF PORTA,1 ;Turn on A1
    BSF PORTA,2 ;Turn on A2
    BSF PORTA,3 ;Turn on A3
    CALL DELAY
    BCF PORTA,0 ;Turn off A0
    BCF PORTA,1 ;Turn off A1
    BCF PORTA,2 ;Turn off A2
    BCF PORTA,3 ;Turn off A3
    RETURN

    ;FLASHING LEDS
    LEDs BSF PORTA,0 ;Turn on A0
    BSF PORTA,1 ;Turn on A1
    BSF PORTA,2 ;Turn on A2
    BSF PORTA,3 ;Turn on A3
    CALL DELAY
    BCF PORTA,0 ;Turn off A0
    BCF PORTA,1 ;Turn off A1
    BCF PORTA,2 ;Turn off A2
    BCF PORTA,3 ;Turn off A3
    CALL DELAY
    GOTO LEDs

    ;************************************************* *********
    ; CONFIGURATION SECTION.

    main BSF STATUS,5 ;change to bank1

    MOVLW B'11110000' ;Bits for mixed I/Os on portA
    MOVWF TRISA

    MOVLW B'00111011' ;Bits for mixed I/Os on portB
    MOVWF TRISB

    MOVLW B'00000000'
    MOVWF OSCCON ;oscillator 31.25kHz

    MOVLW B'00000111' ;prescaler is /256
    MOVWF OPTION_R ;TIMER is 1/32 secs

    BCF STATUS,5 ;return to bank0

    BSF SSPCON,5 ;Set bit 5 to high to enable RB1, RB2 as serial I/O ports

    CLRF PORTB ;clear portB register
    CLRF PORTA ;clear portA register
    CLRF COUNT ;clear count register
    CLRF COUNTA ;clear countA register

    ;************************************************* *********
    ;Program starts now.

    ARM BTFSC PORTA,4 ;INPUT FOR TRANSMITTER
    GOTO ALED
    GOTO ARM

    ALED CALL LED ;CALL LED SUBROUTINE
    GOTO POLLING


    POLLING BTFSS PORTB,0 ;CHECK ULTRASOUND
    GOTO ALARM
    BTFSS PORTB,1 ;CHECK DOOR 1
    GOTO ALARM
    BTFSS PORTB,5 ;CHECK DOOR 2
    GOTO ALARM
    BTFSS PORTB,4 ;CHECK TILT SWITCH
    GOTO ALARM
    GOTO POLLING

    ALARM BSF PORTB,6 ;TURN ON ALARM
    CALL LEDs ;FLASH LEDs
    BTFSC PORTA,4 ;WAIT FOR PORT TO BE LOW
    GOTO ALARM
    CLRF PORTA
    ;BCF PORTA,6 ;TURN OFF ALARM
    ;BCF PORTA,0 ;Turn off A0
    ;BCF PORTA,1 ;Turn off A1
    ;BCF PORTA,2 ;Turn off A2
    ;BCF PORTA,3 ;Turn off A3
    GOTO ARM


    ; initialize eeprom locations

    ORG 0x2100
    DE 0x00, 0x01, 0x02, 0x03


    END ; directive 'end of program'

    So any help would be great also I'm using MPLAB V8 and a PICstart programmer to burn the PIC.

    Thanks again

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898

    Default

    MSSP is for I2C/SPI devices.

    Why not using the Internal USART instead? Way simple! Check For SPBRG, TXSTA, RCSTA register... but yeah.. this pic don't have any UART/USART/EUSART... change to something else... 16F88, 16F628A... or Buy a copy of our beloved PICBASIC PRO COMPILER version... you will do it in seconds with it's built-in software serial features. Buy it HERE

    BUT 31.xxx KHz is not going to be really helpful... 4MHz at very least.

    For serious serial communication i would suggest an external crystal for now.
    Last edited by mister_e; - 16th April 2008 at 20:11.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Apr 2008
    Posts
    5

    Default

    I wish I could afford PICBASIC but can't at the minute. So How would I go about setting up SSP, would it work in the same way for RS232 connection.

    Thanks

Similar Threads

  1. LCDOUT w/custom interface?
    By Mike, K8LH in forum PBP Extensions
    Replies: 4
    Last Post: - 3rd March 2015, 03:54
  2. MXcom "C-BUS" interface to PIC question
    By tcbcats in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st May 2014, 03:59
  3. Replies: 33
    Last Post: - 19th March 2010, 03:02
  4. 'SCI' interface
    By ecua64 in forum Off Topic
    Replies: 0
    Last Post: - 29th September 2005, 16:02
  5. User Configuration Interface in PBP
    By Radiance in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 7th February 2004, 08:00

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