PDA

View Full Version : Help with PIC project



davekav
- 17th April 2008, 11:31
This is my first PIC Project and have enjoyed it so far but having trouble moving forward at the minute.

I'm using MPLAB V8 and a PICstart programmer to burn the PIC, my clicking enable then program and it seens to work but then I got to test it on my breadboard I'm getting nothing out of the pins.


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'

Thanks again

Acetronics2
- 17th April 2008, 12:43
Hi,

Here you are to speak PicBasic Pro ... asm ONLY if incuded into a PbP file ...

Now,

Think to include the right .inc file ( line 2 ) ... LOL !

BUT, mostly ... think to disable the ADC Module and allow pins as DIGITAL !!!

and check if SSP doesn't catch some Port pins ... ( you talk about a link to a PC ... so is it to disable ??? )

Alain

mister_e
- 17th April 2008, 17:23
MOVLW B'00000000'
MOVWF OSCCON ;oscillator 31.25kHz

That's pretty slow :o

Now if you want to communicate with your PC, and make things easier, choose a PIC with a built-in USART. The MSSP module is not going to help you for that.

I know i saw that somewhere else yesterday... not sure where.. but i saw that yesterday...
<hr>
EDIT ahhhhhh...
http://www.picbasic.co.uk/forum/showthread.php?t=8565

davekav
- 17th April 2008, 23:15
Yea steve your correct that was me yesterday also.

Sorry I know this is PICBASIC only but found a lot of good stuff on these forums, just say I forgot about the PC interaction side of things, does my code look ok?

I have include 16F818 on my main code don't know why I left it out.

Thanks again.