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.

Help with writing Assembly to Display Temperature and converting Binary to Decimal

Status
Not open for further replies.
I only have the count code which is in hex for now...

Here is disassembly of count2.hex,

Code:
	processor 16F676
	Radix DEC
#include "P16F676.INC"
	__CONFIG 0x31F4
	ERRORLEVEL -302

	ORG 0
	GOTO   L174
L1:
	MOVWF  52
	CALL   L63
	MOVF   32,0
	IORWF  33,0
	BTFSC  STATUS,Z
	GOTO   L169
	CALL   L163
	BCF    FSR,7
	MOVF   52,0
	XORWF  INDF,1
L11:
	CLRWDT 
	GOTO   L13
L13:
	GOTO   L14
L14:
	INCF   32,1
	BTFSC  STATUS,Z
	INCFSZ 33,1
	GOTO   L11
	XORWF  INDF,1
	GOTO   L169
	MOVLW  8
L21:
	MOVWF  38
	MOVF   55,0
	MOVWF  FSR
	MOVF   53,0
	BTFSC  51,2
	CALL   L58
	BTFSS  51,2
	CALL   L60
	MOVF   54,0
	MOVWF  FSR
	COMF   52,0
	CALL   L64
	MOVF   38,0
	BTFSC  STATUS,Z
	GOTO   L169
	BTFSC  51,0
	CALL   L126
L38:
	MOVF   54,0
	MOVWF  FSR
	RRF    33,1
	RRF    32,1
	MOVF   INDF,0
	IORWF  52,0
	BTFSS  STATUS,C
	XORWF  52,0
	MOVWF  INDF
	CALL   L51
	DECFSZ 38,1
	GOTO   L38
	GOTO   L169
L51:
	MOVF   55,0
	MOVWF  FSR
	MOVF   53,0
	XORWF  INDF,1
	NOP    
	XORWF  INDF,1
	RETURN 
	
L58:
	IORWF  INDF,1
	GOTO   L63
L60:
	XORLW  255
	ANDWF  INDF,1
	GOTO   L64
L63:
	XORLW  255
L64:
	BSF    FSR,7
	ANDWF  INDF,1
	GOTO   L169
L67:
	ANDLW  15
	MOVWF  32
	BCF    STATUS,C
	RLF    32,1
	RLF    32,1
	MOVF   ADCON0,0
	ANDLW  224
	IORWF  32,0
	IORLW  1
	MOVWF  ADCON0
	MOVLW  0
	MOVWF  33
	MOVLW  50
	CALL   L106
	BSF    ADCON0,GODONE
L82:
	BTFSC  ADCON0,GODONE
	GOTO   L82
	CLRF   33
	MOVF   ADRESH,0
	GOTO   L169
L87:
	BSF    STATUS,RP0
	MOVWF  EEADR
	BSF    EECON1,RD
	MOVF   EEDAT,0
	GOTO   L169
	CLRF   163
L93:
	MOVWF  162
L94:
	MOVLW  255
	ADDWF  162,1
	BTFSS  STATUS,C
	ADDWF  163,1
	BTFSS  STATUS,C
	GOTO   L169
	MOVLW  3
	MOVWF  161
	MOVLW  223
	CALL   L106
	GOTO   L94
	CLRF   161
L106:
	ADDLW  232
	MOVWF  160
	COMF   161,1
	MOVLW  252
	BTFSS  STATUS,C
	GOTO   L115
L112:
	ADDWF  160,1
	BTFSC  STATUS,C
	GOTO   L112
L115:
	ADDWF  160,1
	CLRWDT 
	INCFSZ 161,1
	GOTO   L112
	BTFSC  160,0
	GOTO   L121
L121:
	BTFSS  160,1
	GOTO   L125
	NOP    
	GOTO   L125
L125:
	RETURN 
	
L126:
	CLRF   162
	CLRF   163
	GOTO   L133
L129:
	RRF    161,1
	RRF    160,1
	RLF    162,1
	RLF    163,1
L133:
	ADDLW  255
	BTFSC  STATUS,C
	GOTO   L129
	MOVF   163,0
	MOVWF  161
	MOVF   162,0
	MOVWF  160
	GOTO   L169
L141:
	MOVLW  16
	MOVWF  168
	CLRF   161
	CLRF   160
L145:
	RRF    167,1
	RRF    166,1
	BTFSS  STATUS,C
	GOTO   L155
	MOVF   162,0
	ADDWF  160,1
	MOVF   163,0
	BTFSC  STATUS,C
	INCFSZ 163,0
	ADDWF  161,1
L155:
	RRF    161,1
	RRF    160,1
	RRF    165,1
	RRF    164,1
	DECFSZ 168,1
	GOTO   L145
	MOVF   164,0
	GOTO   L169
L163:
	COMF   160,1
	COMF   161,1
	INCF   160,1
	BTFSC  STATUS,Z
	INCF   161,1
	RETURN 
	
L169:
	BCF    STATUS,IRP
	BCF    STATUS,RP1
	BCF    STATUS,RP0
	CLRWDT 
	RETURN 
	
L174:
	BSF    STATUS,RP0
	CLRF   ANSEL
	BCF    STATUS,RP0
	MOVLW  7
	MOVWF  CMCON
	BSF    STATUS,RP0
	BSF    TRISA,3
	BSF    TRISA,5
	BCF    TRISA,2
	BCF    TRISA,1
	BCF    TRISA,0
	BCF    STATUS,RP0
L186:
	CLRWDT 
	BTFSS  PORTA,5
	GOTO   L191
	GOTO   L196
	GOTO   L192
L191:
	GOTO   L281
L192:
	BCF    PORTA,2
	BSF    STATUS,RP0
	BCF    TRISA,2
	BCF    STATUS,RP0
L196:
	CLRF   60
L197:
	CLRWDT 
	MOVLW  10
	SUBWF  60,0
	BTFSC  STATUS,C
	GOTO   L280
	CLRF   59
L203:
	CLRWDT 
	MOVLW  10
	SUBWF  59,0
	BTFSC  STATUS,C
	GOTO   L278
	MOVF   59,0
	CALL   L87
	MOVWF  61
	MOVLW  3
	CALL   L67
	MOVWF  58
	MOVLW  10
	MOVWF  38
	CLRF   39
	MOVF   58,0
	MOVWF  34
	CLRF   35
	CALL   L141
	MOVWF  56
	MOVF   37,0
	MOVWF  57
	MOVLW  30
	ADDWF  56,1
	BTFSC  STATUS,C
	INCF   57,1
	MOVF   60,0
	CALL   L87
	MOVWF  62
	CLRWDT 
	BTFSC  PORTA,5
	GOTO   L235
	GOTO   L281
L235:
	MOVLW  5
	MOVWF  54
	MOVLW  1
	MOVWF  52
	MOVLW  5
	MOVWF  55
	MOVLW  2
	MOVWF  53
	MOVLW  1
	MOVWF  51
	MOVF   61,0
	MOVWF  32
	CLRF   33
	MOVLW  4
	CALL   L21
	MOVLW  5
	MOVWF  54
	MOVLW  1
	MOVWF  52
	MOVLW  5
	MOVWF  55
	MOVLW  2
	MOVWF  53
	MOVLW  1
	MOVWF  51
	MOVF   62,0
	MOVWF  32
	CLRF   33
	MOVLW  4
	CALL   L21
	MOVLW  100
	MOVWF  32
	CLRF   33
	MOVLW  5
	MOVWF  FSR
	MOVLW  4
	CALL   L1
	MOVF   57,0
	MOVWF  35
	MOVF   56,0
	CALL   L93
	INCFSZ 59,1
	GOTO   L203
L278:
	INCFSZ 60,1
	GOTO   L197
L280:
	GOTO   L186
L281:
	BCF    PORTA,2
	BSF    STATUS,RP0
	BCF    TRISA,2
	BCF    STATUS,RP0
	MOVLW  9
	MOVWF  60
L287:
	MOVLW  9
	MOVWF  59
L289:
	MOVF   59,0
	CALL   L87
	MOVWF  61
	MOVLW  3
	CALL   L67
	MOVWF  58
	MOVLW  10
	MOVWF  38
	CLRF   39
	MOVF   58,0
	MOVWF  34
	CLRF   35
	CALL   L141
	MOVWF  56
	MOVF   37,0
	MOVWF  57
	MOVLW  30
	ADDWF  56,1
	BTFSC  STATUS,C
	INCF   57,1
	MOVF   60,0
	CALL   L87
	MOVWF  62
	CLRWDT 
	BTFSS  PORTA,5
	GOTO   L316
	GOTO   L186
L316:
	MOVLW  5
	MOVWF  54
	MOVLW  1
	MOVWF  52
	MOVLW  5
	MOVWF  55
	MOVLW  2
	MOVWF  53
	MOVLW  1
	MOVWF  51
	MOVF   61,0
	MOVWF  32
	CLRF   33
	MOVLW  4
	CALL   L21
	MOVLW  5
	MOVWF  54
	MOVLW  1
	MOVWF  52
	MOVLW  5
	MOVWF  55
	MOVLW  2
	MOVWF  53
	MOVLW  1
	MOVWF  51
	MOVF   62,0
	MOVWF  32
	CLRF   33
	MOVLW  4
	CALL   L21
	MOVLW  100
	MOVWF  32
	CLRF   33
	MOVLW  5
	MOVWF  FSR
	MOVLW  4
	CALL   L1
	MOVF   57,0
	MOVWF  35
	MOVF   56,0
	CALL   L93
	MOVLW  1
	SUBWF  59,1
	BTFSC  STATUS,C
	GOTO   L289
	MOVLW  1
	SUBWF  60,1
	BTFSC  STATUS,C
	GOTO   L287
	GOTO   L186
	ORG 0x2100
	DE 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

	END


and converted to asm file. Unzip and open with notepad or into Mplab.
 

Attachments

  • count2.zip
    1.3 KB · Views: 81
Last edited:
  • Like
Reactions: BmanS

    BmanS

    Points: 2
    Helpful Answer Positive Rating
You will have to show a schematic so we can see how you are connecting the display. It sounds like you are trying to drive the segments from the shift register which isn't the usual way of doing it, especially when there are only two digits.

Basically though, what you need to do is clock out the bit pattern corresponding to the segments you want to illuminate then latch the output of the shiift register so it's pins hold the segment pattern. Something like this which is NOT actual code:

Assume the pattern is in a variable called 'Segments'.
1. set a counter = 0
2. set a mask variable to 0x01
3. AND the mask with 'Segments' (to isolate the single bit in Segments correspondig to the '1' in the mask)
4. if the result is zero, set the data line to the shift register to zero, otherwise set it to '1'.
5. toggle the clock to the shift register (so it moves the bit you just gave it along the register)
6. double the mask value (eg. shift it right so 0x01 would become 0x02 and so on)
7. add 1 to the counter
8. if the counter has reached 8, all the bits are in the shift register so operate the latch signal, otherwise go back to step 3.

Brian.
 
  • Like
Reactions: BmanS

    BmanS

    Points: 2
    Helpful Answer Positive Rating
Well,
For one thing, this is THE assignment for our course. Rather than relying on others to GIVE you the code, you should sit down and do some math on the conversion. Plenty of samples out there and information on converting to BCD from binary. Plenty of algorithms out there as well.

But just asking others to GIVE you the answer for an assignment....not really very cool.

We'll talk in class.

- - - Updated - - -

Ya know,
That's cheating....
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top