RC RC receiver input into PIC16f627 to turn LED on

Thread Starter

vane

Joined Feb 28, 2007
185
Basically, what i would like help on is the simple logic behind how you go about measuring 1ms - 2ms pulses every 20ms. I would preferably need help with assembly as that is the program i am currently using

At the moment I only know how to do it with just one push button

Rich (BB code):
EFFECT_1	BTFSC	PORTA,SW1
		GOTO	EFFECT_1
E1		MOVLW	B'00100000'	;
		MOVWF	PORTB
		CALL	DELAY_ROUTINE
		MOVLW	B'00110000'	;
		MOVWF	PORTB...
Any help would be greatly appreciated.
 

Thread Starter

vane

Joined Feb 28, 2007
185
I have just tried an example on the internet but it wont flash an LED. How do you know if your chip has burnt out?

EDIT: No, it hasn't burnt out, i think i have a faulty DIL socket on my experiment board

Thanks so much for that web link! i will examine it thoroughly in the morning!
 
Last edited:

Thread Starter

vane

Joined Feb 28, 2007
185
Anyone know why i cant call my subroutines in this code?

Rich (BB code):
;Constants

08h	equ	C8h		;Set COUNT1 number (200)
09h	equ	Ah		;Set COUNT2 number (10)
STATUS	equ	03h                 ;Address of the STATUS register
TRISA	equ	85h                 ;Address of the tristate register for port A
PORTA	equ	05h                 ;Address of Port A
COUNT1	equ	08h                 ;First counter for delay loops
COUNT2	equ	09h                 ;Second counter for delay loops

;Port Setup

	bsf	STATUS,5	;Bank 1
	movlw	01h		;Send to W
	movwf	TRISA		;Send w to TRISA
	bcf	STATUS,5	;Bank 0

;Check if it is jumpered

Start	movlw	01h
	movwf	PORTA

	BTFSC	PORTA,0		;see if it is high

	call	1msDelay

;1ms delay

	call	1msDelay

;Now switching to low for 20ms pulse

	movlw	00h
	movwf	PORTA

;20ms Pulse

ROUTINE	COUNT	equ 20
LABEL21	decfsz	COUNT,1
	Goto	LABEL21
	
;Restart

	goto	Start






;Subroutines;


1msDelay

Loop1	decfsz	COUNT1,1     ;This second loop keeps the LED
	goto	Loop1              ;turned off long enough for us to
	decfsz	COUNT2,1      ;see it turned off
	goto	Loop1              ;
return
Apparently there are 10 errors in this, i can't find them :s
 
Last edited:

bertus

Joined Apr 5, 2008
20,528
Hello,

Is a label not supposed to have a semicolon ":" behind it?
So use,
1msDelay: as label (also with other labels used).

Greetings,
Bertus
 

jpanhalt

Joined Jan 18, 2008
9,338
Hello,

Is a label not supposed to have a semicolon ":" behind it?
So use,
1msDelay: as label (also with other labels used).

Greetings,
Bertus

I use MPLAB IDE and no colon (or semicolon) is used after labels. The semicolon sets off comments.

I have a very similar program that works. It would be helpful if Vane would give more detail about how he knows it is not working? For example, is it not compiling, can he step through it, what errors is he getting, and so forth.

John
 

jpanhalt

Joined Jan 18, 2008
9,338
Here is a screen print of a portion of the code. Sorry for the fuzziness, I wanted to use the screen print so the exact format and colors would be preserved. Note the subroutine calls and returns (retlw).




John
 

jpanhalt

Joined Jan 18, 2008
9,338
Ah, your "return" is in the wrong column. Tab it over one. Also, my compiler complains when I use "return", but still works, as I recall. Use "retlw 0"

John
 

Thread Starter

vane

Joined Feb 28, 2007
185
Right done that, but that hasn't stopped it saying any other of the errors

I am just using Notepad to write it and using MPASMWIN to compile
 

jpanhalt

Joined Jan 18, 2008
9,338
What are the other errors?

Everyone has his own preference. I have tried notepad, but get some dumb errors. MPLAB helps in format and spelling. If the instruction is wrong, it won't change to blue and so forth.

John
 

jpanhalt

Joined Jan 18, 2008
9,338
Here are a couple of quick obserbvations:

1) Labels must begin with an alpha character or underscore. That takes care of some of the errors.

2) At least one error was simple misspelling.

Try fixing those and see what happens.

John
 

Thread Starter

vane

Joined Feb 28, 2007
185
For some reason it does not look like it accepts:-

Rich (BB code):
08h	equ	C8h		;Set COUNT1 number (200)
09h	equ	Ah		;Set COUNT2 number (10)
After this it has 1 more error
 

jpanhalt

Joined Jan 18, 2008
9,338
I think that is the wrong way to put a value into a register. Go to the code I posted and look at the section beginning Dly_120.

In other words, your equates should look something like:

d1 equ 08h
d2 equ 09h

Then in your code you will have something like:
Rich (BB code):
       clrwdt           ; it's a good idea to clear the wdt
       movlw     c8h     ;  puts d'200 in w
       movwf     d1  ;puts the value in w into the register you have  defined for d1, namely 08h
PS: Sorry for the lousy looking code. I haven't got the knack of writing it in Notepad and posting with the code tags.

John
 

jpanhalt

Joined Jan 18, 2008
9,338
Where you put it depends on how you are going to use it. I just set up d1, d2, d3, etc. in the equates. Then when I need a delay, I load the correct values in each register. That is, those few registers take care of all of my delays.

I use a Delay Code Generator on the Internet to calculate nested delay loops. That generator uses d1, etc., and I saw no reason to change. I just cut and paste, then tweak using the simulator and stopwatch functions, if needed. However, for what I was doing, it was close enough ±2 cycles.

John

Edit: Here's a link to the code generator: http://www.piclist.com/techref/piclist/codegen/delay.htm
 

Thread Starter

vane

Joined Feb 28, 2007
185
haha, i went through all the workings out! working out if it has a 20mhz clock, 1 millisecond is 2000 cycles!
 

jpanhalt

Joined Jan 18, 2008
9,338
With a PIC, a cycle is f/4 or 1/5 x10E-6 seconds per cycle with a 20 MHz clock. Thus, 5000 cycles x 1/5 x10E-6 = 0.001 seconds.

John
 
Top