Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

source code problem

Status
Not open for further replies.

imisendo_4036

New Member
hi....need help
this is my source code that is to maintain DC motor speed....
unfortunately, when i run using mplab ide...
its not function....stack pointer doesn't move till de end...
i'm already compile but there is no error....
can anyone who is experience help me...
wuts the problem wif my source code...
n for ur info i'm using pic16f873


this is my code:

;PROGRAM IS TO CONTROL DC MOTOR SPEED
;BY ZULHILMI USING PIC16F873

;*****DECLARATION*****

PROCESSOR 16F873
#include "p16F873.inc"
__CONFIG _HS_OSC & _WDT_OFF & _PWRTE_ON & _LVP_OFF
errorlevel -302

;*****LABEL****

speed equ d'8'
change equ d'1'
led equ h'20'

;****PROGRAM START*****

goto 0
goto init
org 4
goto init

;*****INITIAL PROCESS******

init

;*****PORT****
bsf 03h,5
movlw b'00000001'
movwf 85h
clrf 86h
clrf 87h
bcf 03h,5

;****A/D CONVERTER*****

movlw b'10000101'
movwf 1Fh
bsf 03h,5
movlw b'00001110'
movwf 9Fh
bcf 03h,5

;*****PWM*****

clrf 11h
movlw b'11111111'
movwf 15h
bsf 03h,5
movlw d'254'
movlw 92h
bcf 03h,5
movlw b'00000110'
movwf 12h
movlw b'00001100'
movwf 17h

;*****COMPARE MODE*****

clrf 0Fh
clrf 0Eh
movlw h'61'
movwf 1Ch
movlw h'A8'
movwf 1Bh
movlw b'00000001'
movwf 10h
movlw b'00001011'
movwf 1Dh

;****INTERRUPTION CONTROL******

bsf 03h,5
movlw b'00000001'
movwf 8Dh
bcf 03h,5
movlw b'11000000'
movwf 18Bh

wait

goto $

;*****INTERRUPTION PROCESS*****

int
clrf 0Dh
ad_check
btfsc 1Fh,2
goto ad_check
movlw 1Eh
sublw speed
btfsc 03h,0
goto check1

;****LOW SPEED*****
movlw 15h
addlw change
btfss 03h,0
movwf 15h
goto led_cont

check1
btfsc 03h,2
goto led_cont

;****FAST SPEED******
movlw change
subwf 15h,1
btfsc 03h,0
goto led_cont
clrf 15f

;******LED CONTROL******

led_cont
comf 15h,0
movwf led
movlw b'00010000'
subwf led,0
btfsc 03h,0
goto led1
movlw b'00000000'
goto int_end
led1
movlw b'00100000'
subwf led,0
btfsc 03h,0
goto led2
movlw b'00000001'
goto int_end
led2
movlw b'01000000'
subwf led,0
btfsc 03h,0
goto led3
movlw b'00000011'
goto int_end
led3
movlw b'01100000'
subwf led,0
btfsc 03h,0
goto led4
movlw b'00000111'
goto int_end
led4
movlw b'10000000'
subwf led,0
btfsc 03h,0
goto led5
movlw b'00001111'
goto int_end
led5
movlw b'10100000'
subwf led,0
btfsc 03h,0
goto led6
movlw b'00011111'
goto int_end
led6
movlw b'11000000'
subwf led,0
btfsc 03h,0
goto led7
movlw b'00111111'
goto int_end
led7
movlw b'11100000'
subwf led,0
btfsc 03h,0
goto led8
movlw b'01111111'
goto int_end
led8
movlw b'11111111'

;******END INTERRUPTION******
int_end
movwf 06h
retfile

;**********END OF DC MOTOTR SPEED CONTROLLER*******

END

end
 
A very quick look at your code makes me think that the code at location 4 should be goto int and not goto init.

Mike.
 
Last edited:
i already change init to main...is it allowed??....
n the stack running but how to make sure it's running in real time????
or i must burn in pic 1st to confirm??????
 
__CONFIG _HS_OSC & _WDT_OFF & _PWRTE_ON & _LVP_OFF

what is the meaning with this instruction??
can anyone xplain??

i've read about the configuration word with address at 2007h...
should i write to this address to enable this......(__CONFIG _HS_OSC & _WDT_OFF & _PWRTE_ON & _LVP_OFF)
 
imisendo_4036 said:
this is my source code that is to maintain DC motor speed....
The code is by Seiichi Inoue from this site:
code:
**broken link removed**
And it actually has comments and uses proper labels for the SFRs! Why did you strip this data out and possibly corrupt the code with typo's?
Main page:
**broken link removed**
Why don't you follow the instructions on the site? Though I don't think this is the best way to control motor speed. An optical encoder, instead of another motor, would make more sense to me.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top