PDA

View Full Version : Interface for 16f818



davekav
- 16th April 2008, 16:59
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.

duncan303
- 16th April 2008, 17:29
Welcome


Any help would be great thanks.

Any code/details would be great thanks

Duncan

__________________

davekav
- 16th April 2008, 20:20
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 <p16F818.inc> ; 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

mister_e
- 16th April 2008, 21:05
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 (http://www.rentron.com/PicBasic/products/PBP_E.htm)

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.

davekav
- 17th April 2008, 12:33
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