show (hexa)decimal values on display from ADC or DIP
authorTero Marttila <terom@fixme.fi>
Sat, 08 May 2010 20:59:22 +0300
changeset 25 33496b1a964f
parent 24 8100038e3d58
child 26 db2ec641c955
show (hexa)decimal values on display from ADC or DIP
led7seg.inc
led7seg.s
--- a/led7seg.inc	Sat May 08 20:58:32 2010 +0300
+++ b/led7seg.inc	Sat May 08 20:59:22 2010 +0300
@@ -87,7 +87,54 @@
 
     ; Done
         ret
- 
+
+;; Display an 8-bit hexadecimal value on the display
+;;  Input: r16
+LED7_ShowHex:
+        ; base16
+        ldi         r17, 16 
+
+        ; 1's
+        call        div8u
+        
+        ; r16 = result, r15 = remainder
+        mov         r17, r15 
+
+    ; Continue
+        rjmp        LED7_Show
+
+;; Display an 8-bit decimal value on the display
+;;  Input: r16
+LED7_ShowDec:
+        ; base10
+        ldi         r17, 10
+
+        ; 1's
+        call        div8u
+        mov         r8, r15
+
+        ; 10's
+        call        div8u
+        mov         r9, r16         ; 100's
+        
+        ; 1's from r8
+        rcall       LED7_LoadChar
+        mov         r17, r8
+
+        ; 10's from r15
+        mov         r8, r15
+        rcall       LED7_LoadChar
+        mov         r16, r8
+           
+        ; Set dots for 100's 
+        sbrc        r9, 0
+        ori         r17, 0b10000000 ; +100
+        sbrc        r9, 1
+        ori         r16, 0b10000000 ; +200
+
+    ; Continue
+        rjmp        LED7_ShowRaw
+
 ;; Display a single digit on the display
 ;;  Input: r16, r17
 LED7_Show:
@@ -95,9 +142,9 @@
         rcall       LED7_LoadChar
         mov         r16, r8
 
-        mov         r8, r16
+        mov         r8, r17
         rcall       LED7_LoadChar
-        mov         r16, r8
+        mov         r17, r8
         
     ;; Continue
 
--- a/led7seg.s	Sat May 08 20:58:32 2010 +0300
+++ b/led7seg.s	Sat May 08 20:59:22 2010 +0300
@@ -35,8 +35,38 @@
 
 ;; Utils
 .include "delay.inc"
+.include "div.inc"
 
-;; Count down from 9
+Sleep_ADC:
+        ; delay
+        rcall       ADC_Read8 
+        
+        ; Sleep for 64 * var timer cycles
+        ldi         r17, 64
+        mul         r16, r17
+        mov         XL, r0
+        mov         XH, r1 
+
+        rjmp       Timer_Sleep
+
+;; Show ADC value
+Main_ShowADC:
+        ; load value to r16
+        mov         r16, r10
+        ; rcall       ADC_Read8
+
+        ; display from r16
+        rcall       LED7_ShowHex
+        
+        ; *g*
+        ldi         XL, 0
+        ldi         XH, 16
+        rcall       Timer_Sleep
+
+        ; continue
+        rjmp        Main_ShowADC
+
+;; Count down from F
 ; Returns once we've hit zero
 Main_Countdown:
         ; init from F
@@ -45,6 +75,7 @@
 _count_loop:
         ; display
         mov         r16, r24
+        mov         r16, r24
         rcall       LED7_Show
 
         ; exit if zero
@@ -55,7 +86,7 @@
         dec         r24
 
         ; wait...
-        rcall        Delay_1s
+        rcall       Sleep_ADC
 
         ; next
         rjmp        _count_loop
@@ -64,21 +95,52 @@
         ; done
         ret
 
+;; Count up from 00 -> 255
+; Returns once done
+Main_CountUp:
+        ; init from 0
+        ldi         r24, 0
+
+_countup_loop:
+        ; display
+        mov         r16, r24
+        rcall       LED7_ShowDec
+
+        ; wait...
+        rcall       Sleep_ADC
+
+        ; exit if zero
+        cpi         r24, 255
+        breq        _countup_end
+
+        ; count up
+        inc         r24
+
+        ; continue
+        rjmp        _countup_loop
+
+_countup_end:
+        ; done
+        ret
+
 ;; Blink between dot and empty
 Main_Blink:
 _blink_loop:
         ; dot
         ldi         r16, LED7_DOT
+        ldi         r17, LED7_EMPTY
         rcall       LED7_Show
 
         ; wait...
-        rcall       Delay_1s
+        rcall       Sleep_ADC
         
         ; empty
         ldi         r16, LED7_EMPTY
+        ldi         r17, LED7_DOT
         rcall       LED7_Show
         
-        rcall       Delay_1s
+        ; wait... 
+        rcall       Sleep_ADC
         
         ; loop
         rjmp        _blink_loop
@@ -97,16 +159,8 @@
         rcall       LED7_ShowRaw
 
         ; delay
-        rcall       ADC_Read8 
-        ;mov         r16, r10
-
-        ldi         r17, 64
-        mul         r16, r17
-        mov         XL, r0
-        mov         XH, r1 
-
-        rcall       Timer_Sleep
-
+        rcall       Sleep_ADC
+        
         ; next segment
         lsl         r24
         
@@ -144,10 +198,9 @@
         rcall       LED7_Init    
     
     ; Run
-        ; spin!
-        rcall       Main_Spin
-        
-        ; count!
+        rcall       Main_ShowADC
+        ; rcall       Main_Spin
+        ; rcall       Main_Countup
         ; rcall       Main_Countdown
         ; rcall       Main_Blink