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.

[PIC] decimal to bcd converting

Status
Not open for further replies.

rasool4

Newbie level 1
Joined
Feb 11, 2015
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
8
hi
i use 16f877a programmer for programming and for showing 3digit number in 7segment i use decimal to bcd code my code it work well when i use goto for calling decimal to bcd code but when i use call instruction for calling this code itis not work well . this is my program
Code:
.
.
.
         PAGESEL     DECIMAL
         CALL       DECIMAL                 ;CONVERT IDECIMAL TO BCD
        PAGESEL     $
.
.
.
DECIMAL
        SWAPF       MATH_HIGH,W             
        ANDLW       0FH                       
        ADDLW       0F0H                     
        MOVWF       THOUSANDS               
        ADDWF       THOUSANDS,F               
        ADDLW       0E2H                    
        MOVWF       HUNDREDS               
        ADDLW       32H                     
        MOVWF       ONES                     
        MOVF        MATH_HIGH,0               
        ANDLW       0FH                       
        ADDWF       HUNDREDS,F           
        ADDWF       HUNDREDS,F              
        ADDWF       ONES,F                    
        ADDLW       0E9H                  
        MOVWF       TENS                      
        ADDWF       TENS,F                   
        ADDWF       TENS,F                   
        SWAPF       MATH_LOW,W               
        ANDLW       0FH                      
        ADDWF       TENS,F                   
        ADDWF       ONES,F                    
        RLF         TENS,F             
        RLF         ONES,F             
        COMF        ONES,F            
        RLF         ONES,F              
        MOVF        MATH_LOW,W         
        ANDLW       0FH                  
        ADDWF       ONES,F              
        RLF         THOUSANDS,F         
        MOVLW       07H                 
        MOVWF       TENK               
        MOVLW       0AH                 
LB1  
        ADDWF       ONES,F               
        DECF        TENS,F               
        BTFSS       3,0                
        GOTO        LB1                
LB2    
        ADDWF       TENS,F            
        DECF        HUNDREDS,F          
        BTFSS       3,0                
        GOTO        LB2                
LB3   
        ADDWF       HUNDREDS,F        
        DECF        THOUSANDS,F       
        BTFSS       3,0                
        GOTO        LB3               
LB4  
        ADDWF       THOUSANDS,F       
        DECF        TENK,F           
        BTFSS       3,0                
        GOTO        LB4               
   RETURN


i dont now why when i use below code for callind decimal part it works well
         PAGESEL     DECIMAL
        goto      DECIMAL             
        PAGESEL     $
comebakdecimal
.
.
.
but when i use call instruction for calling this part it is not work
 
Last edited by a moderator:

There is nothing in your code that will stop it from being called correctly. The PIC has only 8 levels of stack, perhaps you have exceed this.
 

If you must run "CALL DECIMAL" as the first instruction, then do it like this:

Code:
   call decimal
   goto end
decimal
...... your program here.....
   return
end   end

Then it should work. Without "goto end" the program will come back after hitting "RETURN", it will execute DECIMAL again and after hitting RETURN for the second time, the stack pointer would be screwed and wonders into no_where_land.

Allen
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top