Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

7 segment display - PIC16F84

Status
Not open for further replies.

Always_Confused_Sudent

Junior Member level 3
Joined
Dec 26, 2003
Messages
28
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
321
Okay, this is my first program ever for a microcontroller , it's supposed to increment the digit that will be displayed on each interrupt,
interrupt source is RB4-RB7.
RA0-RA3 , RB0-RB2 are connected to the 7-segment display,
can anyone check if this is correct and tell me his opinion about the code in general ?



Code:
	Processor 16f84A
    #include "p16f84a.inc"

    __config _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC 



temp equ 0x0c
temp1 equ 0x0d




	org 0x00          
	goto Main      

	org 0x04          
	BCF INTCON,0

    banksel PORTA
	MOVF temp1,0
	addwf PCL,1
	MOVLW b'01000000' ; zero
	goto display
	MOVLW b'01111001' ; one
	goto display
	MOVLW b'00100100' ; two
	goto display
	MOVLW b'00110000' ; three
	goto display
	MOVLW b'00011001' ; four
	goto display
	MOVLW b'00010010' ;five
	goto display
	MOVLW b'00000010' ;six
	goto display
	MOVLW b'01111000' ;seven
	goto display
	MOVLW b'00000000' ;eight
	goto display
                MOVLW b'00011000' ;nine           
	goto display
	MOVLW 0x00 
	MOVWF temp1
    RETFIE
;;;;;;;;;;;;;;;;;;;;;;;;;;;


display
 banksel PORTA
		MOVWF temp
		MOVLW b'00001111'
		ANDWF temp,0
		MOVWF PORTA
		SWAPF temp,0
		ANDLW b'00001111'
		MOVWF PORTB
	INCF temp1
	INCF temp1
		RETFIE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Main
	banksel TRISA
	CLRF TRISA
	banksel TRISB
	MOVLW b'11110000'
	MOVWF TRISB
    banksel INTCON

	MOVLW 0x88
	MOVWF INTCON
	MOVWF temp
loop                 ;;;i added this loop to show myself how interrupt works 
    DECFSZ temp
	goto loop
	goto loop
	END
 

I didn´t test the code, but if the code works like you need in your application, then it is ok.

I think we need to optimize the code, just it.
 

The code seems correct but you shouldn't execute code in the interrupt rotine. Just raise up a flag and execute the code in main rotine. In this case you'll have just an interrupt, so il will work fine, but if you use more you will loose track of interrupts ( interrupts are disable when executing interrupt rotine).
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top