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.

help using tables

Status
Not open for further replies.

josi

New Member
hi! i'm learning how use how to display on a 7-segment using a pic 16f877. i'm tryin to call a table and display the values via portD wich is connected to the 7-segment! can anyone check my code coz it's not workin! thanx

Code:
LIST	     p=16F877		                    
#include    <P16F877.inc>		                
__config    _XT_OSC & _PWRTE_ON & _WDT_OFF &_LVP_OFF   
;*****Equates**********************************************
status       equ 03h
PortA        equ 05h
PortD        equ 08h
TRISA        equ 85h
TRISD        equ 88h
count0       equ 25h
count1       equ 26h
count2       equ 27h
pcl          equ 02h
pclath       equ
;******Main Program****************************************
    org         00h   
    bsf         status,RP0        
    movlw     B'11111111'       ; set portA as input
    movwf    TRISA
    movlw     B'00000000'       ; set PortD as outpout
    movwf    TRISD
    movlw	    D'6'
    movwf	    ADCON1
    bcf         status,RP0 

start
   call        Table
   movwf    PortD
   goto       start
    
Table
   retlw     b'11101111'            ;display 0
   call       delay
   retlw     b'10001001'            ;display 1
   call       delay
   retlw     b'11010111'            
   call       delay
   retlw     b'11011101'
   call       delay
   retlw     b'10111001'
   call       delay
   retlw     b'01111101'
   call       delay
   retlw     b'00111111'
   call       delay
   retlw     b'11001001'
   call       delay
   retlw     b'11111111'
   call       delay
   retlw     b'11101111'       
   call       delay
  


delay                                  ;delay routine
   movlw  03h            
   Movwf  count2

Loop    
  decfsz   count0,1

  Goto     Loop

 Decfsz  count1,1

 Goto     Loop
 
 Decfsz  count2,1

 Goto     Loop

 Return 
 end
 
You can't have delays in the middle of your table. You have to access your table, write it to the port and then do a delay.

I tidied your code to how I think it should be. See if this works,
Code:
		list	p=16F877		                    
		#include <P16F877.inc>  
		__config _XT_OSC & _PWRTE_ON & _WDT_OFF &_LVP_OFF   

;*****Equates**********************************************  
count0		equ	25h
count1		equ	26h
count2		equ	27h
digit		equ	28h

;******Main Program****************************************  
		org	00h   
		bsf	STATUS,RP0        
		movlw	B'11111111'	; set portA as input
		movwf	TRISA
		movlw	B'00000000'	; set PortD as outpout
		movwf	TRISD
		movlw	D'6'
		movwf	ADCON1
		bcf	STATUS,RP0 
		clrf	digit
start		movfw	digit
		call	Table
		movwf	PORTD
		call	delay
		incf	digit,F
		movfw	digit
		xorlw	d'10'
		btfsc	STATUS,Z
		clrf	digit
		goto	start
			 
Table
		addwf	PCL,F
		retlw	b'11101111'	;display 0
		retlw	b'10001001'	;display 1
		retlw	b'11010111'            
		retlw	b'11011101'
		retlw	b'10111001'
		retlw	b'01111101'
		retlw	b'00111111'
		retlw	b'11001001'
		retlw	b'11111111'
		retlw	b'11101111'      			 


delay					;delay routine 
		movlw	03h            
		movwf	count2
Loop		decfsz	count0,1
		goto	Loop
		decfsz	count1,1
		goto	Loop
		decfsz	count2,1
		goto	Loop
		return	 

		end

I added the variable digit to keep track of what to display. Try running the above in the simulator to get an idea of how it is working. You might want to rem the call delay line when your simulating.

Mike.
 
hi,
In addition to Pommie's advise.

Relook at the segment patterns,

Im assuming PORTD.0 = seg 'a' D.1= seg 'b' etc....
 
I added the variable digit to keep track of what to display. Try running the above in the simulator to get an idea of how it is working. You might want to rem the call delay line when your simulating.

Mike.[/QUOTE]
i tried what u said mike but it's not workin, i'm getting one segment on at a time! i don't know what to do!
 
That code should work. The code is written to use a common cathode display, is this what you are using? If you are using a common anode display then swap the 1s and 0s in the retlw lines.

If it still doesn't work then you need to post a schematic.

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top