• 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.

Is there anything wrong with my codes?pls help...

Status
Not open for further replies.

aldrinsi

New Member
Code:
	list      p=16f84A         ; list directive to define processor
	#include <p16F84A.inc>        ; processor specific variable definitions
	errorlevel  -302 , -207             ; suppress message 302 from list file

	__config _XT_OSC & _CP_OFF & _PWRTE_OFF & _WDT_OFF

var1  	equ 0x0C

	ORG     0x00            ; processor reset vector
	GOTO    main              ; go to beginning of program
	

	ORG     0x004             ; interrupt vector location
	NOP
	RETFIE                    ; return from interrupt

 
main:
	MOVLW 0x00
	BSF STATUS, RP0
	MOVWF TRISB
	BCF STATUS, RP0

k:	MOVLW 0xFF
	MOVWF PORTB
	CALL delay

	MOVLW 0X00
	MOVWF PORTB
	CALL delay
	GOTO k

delay:
	MOVLW 0xFF
	MOVWF var1
h:	DECFSZ var1, F
	GOTO h
	RETURN	

	end
i'm new in microcontroller, and i'm using PIC16F84A. I'm trying to create another program which will turn the LEDs on PORTB ON and OFF, but it only result in illuminating all the LEDs in PORTB. why?is there anything wrong with my codes?
your reply will be much appreciated!:)
 

blueroomelectronics

Well-Known Member
This would be a good time to learn how the MPLAB simulator works. You can single step through your code and see the results with a watch window.
 

Pommie

Well-Known Member
Most Helpful Member
The LEDs are probably flashing. However, they are flashing so fast that they look like they are permanently on. Try making your delay longer.

Mike.
 

Nigel Goodwin

Super Moderator
Most Helpful Member
Your delay is probably too small?, so while the LED's are actually flashing, it's too fast for you to see.

Check my first tutorial, which does what you want.

You also shouldn't really be using the long obselete 16F84, the 16F628 (cheaper and better) replaced it last century.
 

Pommie

Well-Known Member
Most Helpful Member
Just noticed that you have already asked this question and got a reply and working code from Eric. Why did you post this thread?

Mike.
 

aldrinsi

New Member
The LEDs are probably flashing. However, they are flashing so fast that they look like they are permanently on. Try making your delay longer.

Mike.
Code:
	list      p=16f84A         ; list directive to define processor
	#include <p16F84A.inc>        ; processor specific variable definitions
	errorlevel  -302 , -207             ; suppress message 302 from list file

	__config _XT_OSC & _CP_OFF & _PWRTE_OFF & _WDT_OFF

d1  	equ 0x0C
d2		equ 0x0D
d3 		equ	0x0E
	ORG     0x00            ; processor reset vector
	GOTO    main              ; go to beginning of program
	

	ORG     0x004             ; interrupt vector location
	NOP
	RETFIE                    ; return from interrupt

 
main:
	MOVLW 0x00
	BSF STATUS, RP0
	MOVWF TRISB
	BCF STATUS, RP0

k:	MOVLW 0xFF
	MOVWF PORTB
	CALL delay

	MOVLW 0X00
	MOVWF PORTB
	CALL delay
	GOTO k

delay:
	MOVLW 0xFF
	MOVWF d3
j:	MOVLW 0xFF
	MOVWF d2
i:	MOVLW 0xFF
	MOVWF d1
h:	DECFSZ d1, F
	GOTO h
	DECFSZ d2, F
	GOTO i
	DECFSZ d3, F
	GOTO j
	RETURN	

	end
i already extend the delay time, but why do i still having the same result?:(
 

ericgibbs

Well-Known Member
Most Helpful Member
hi

I would advise you not to start using single characters to represent labels in your program. eg: k, j, i, etc

Use label names which mean something to someone else looking at your program.

An example of poor programming is that 'GOTO k'
 
Last edited:

be80be

Well-Known Member
Look at the delays in this code I use this Delay Code Generator
Code:
	list      p=16f84A         ; list directive to define processor
	#include <p16F84A.inc>        ; processor specific variable definitions
	errorlevel  -302 , -207             ; suppress message 302 from list file

	__config _XT_OSC & _CP_OFF & _PWRTE_OFF & _WDT_OFF

 	cblock  h'0C'
	d1
	d2
	d3
	endc
	ORG     0x00            ; processor reset vector
	GOTO    main              ; go to beginning of program
	

	ORG     0x004             ; interrupt vector location
	NOP
	RETFIE                    ; return from interrupt

 
main:
	MOVLW 0x00
	BSF STATUS, RP0
	MOVWF TRISB
	BCF STATUS, RP0

kmain:	MOVLW 0xFF
	MOVWF PORTB
	CALL delay

	MOVLW 0X00
	MOVWF PORTB
	CALL delay
	GOTO kmain

; Delay = 0.5 seconds
; Clock frequency = 4 MHz

; Actual delay = 0.5 seconds = 500000 cycles
; Error = 0 %



delay
			;499994 cycles
	movlw	0x03
	movwf	d1
	movlw	0x18
	movwf	d2
	movlw	0x02
	movwf	d3
Delay_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay_0

			;2 cycles
	goto	$+1

			;4 cycles (including call)
	return
end
 
Last edited:

ericgibbs

Well-Known Member
Most Helpful Member
your delay in the last posting is wrong.

If you want to experiment with delays just change the code marked in BLUE.

Code:
Delay:
			;999997 cycles
[COLOR="Blue"]	movlw	0x08
	[COLOR="Black"]movwf	d1[/COLOR]
	movlw	0x2F
	[COLOR="Black"]movwf	d2[/COLOR]
	movlw	0x03
	[COLOR="Black"]movwf	d3[/COLOR]
[/COLOR]Delay_0
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	$+2
	decfsz	d3, f
	goto	Delay_0
			;3 cycles
	goto	$+1
	return
 
Last edited:
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top