Fórum témák

» Több friss téma
Fórum » PIC kezdőknek
 
Témaindító: Placi84, idő: Okt 3, 2005
Témakörök:
- A PIC ÖSSZES Vdd és Vss (AVdd és AVss) (tápfeszültség) lábát be kell kötni!
- A táplábak mellé a lehető legközelebb 100nF-os KERÁMIA kondenzátorokat kell elhelyezni.
- Az MCLR lábat, 10kohm-mal fel kell húzni a Vdd tápfeszültségre.
- Külső kvarc használatakor 4MHz-ig XT, a fölött pedig HS konfigurációt kell beállítani.
- Stabilizált tápegységet kell használni, a kapcsoló üzemű "telefon töltő" adapterek okozhatnak hibákat.
- Programozáshoz, használj lehetőleg PICKIT2 vagy 3 programozót. Kerülendő a JDM (soros porti) programozó.
- A PIC adatlapja (PDF), tartalmazza a lábak kiosztását és a PIC minden paraméterét. Az adatlap ingyen letölthető!
- Egyes PIC típusoknál az RA4 nyitott nyelőelektródás (Csak lefelé húz L szintre, H szintet nem ad ki!)
- Ha a PGM lábat digitális ki-/bemenetnek használod, az alacsony feszültségű programozási lehetőséget le kell tiltani.
Lapozás: OK   360 / 1222
(#) n_yálastrubadúr hozzászólása Jan 29, 2013 /
 
Jó éjszakát!
Most hogy mindegyik demo-panelen együttesen akarom az uart-ot használni, alapvető problémákba ütközöm. Az egyiken megjelenítésre van 2db 4digit -es 14 szegmenses multiplexált kijelző. Hasonlóan próbálkozom a bináris értéket decimálisra váltani mint assemblyben. Ami megy is, de kipróbáltam hogy gyorsan léptetetm magát az értéket és láthatóan súlyosan lassú, tehát erősen remeg a kijelzés. És jól láthatóan értékfüggő a remegés, szóval biztos hogy a konverziós művelet a hibás. Mondjuk nem 100%, mert van egy tábla is újdonságként. Megnéztem az asm kódját , le is szimuláltam. Az egész olyan 150-350us. Ezt nem lehetne látnom, szerintem.
Megcsináltam az átalakítást két verzióban is. Ittvan mind 2. Értelemszerűen van fölé írva, csak az egyik verzió ami mehet.
  1. const char table[10]={0xED,0xC,0xBB,0x3F,0x5E,0x77,0xF7,0x2C,0xFF,0x7F};
  2.  
  3.         void main () {
  4.         init ();
  5.         for (;;){
  6.  
  7.         inc1 ++;
  8.         if (inc1 == 1)inc ++;
  9.         xxx = inc;
  10.  
  11.         xxx = 253;
  12.  
  13. ///////////////////// 1-es verzió ////////////////////////
  14. s100:
  15.         xxx = xxx -100;
  16.         if (c) {numh ++; goto s100;}
  17.         else xxx = xxx + 100;
  18. s10:
  19.         xxx = xxx -10;
  20.         if (c) {numt ++; goto s10;}
  21.         else xxx = xxx + 10;
  22. s1:
  23.         xxx = xxx -1;
  24.         if (c) {num ++; goto s1;}
  25.         else xxx = xxx + 1;
  26.  
  27. ///////////////////// 2-es verzió ////////////////////////
  28.  
  29. //      while (xxx >= 100){ xxx= xxx-100; numh++; }    
  30. //      while (xxx >= 10){ xxx= xxx-10; numt++; }
  31. //      while (xxx >= 1){ xxx= xxx-1; num++; }
  32.  
  33. /////////////////////////////////////////////////////////
  34.  
  35.         pd = 1; pb = table[num];
  36.         __delay_us(20);
  37.         pd = 0; pb = 0;
  38.         pd = 8; pb = table[numt];
  39.         __delay_us(20);
  40.         pd = 0; pb = 0;
  41.         pd = 2; pb = table[numh];
  42.         __delay_us(20);
  43.         pd = 0; pb = 0;
  44.         num = 0; numt = 0; numh = 0;
  45. }
  46. }
(#) Kovabe hozzászólása Jan 29, 2013 /
 
Sziasztok
Esetleg van tapasztalata valakinek 16F628A-val hogy hogyan müködik az RA4 láb, felfelé is huz vagy csak le?
(#) pjg válasza Kovabe hozzászólására (») Jan 29, 2013 /
 
Open Drain Output
(#) Kovabe válasza pjg hozzászólására (») Jan 29, 2013 /
 
Ok csak olvastam a fejlécben hogy némely PIC csak lefelé huzza RA4-et.
(#) pjg válasza Kovabe hozzászólására (») Jan 29, 2013 /
 
Ez is. Mint az open kollektor. Kell neki pár k Ohm ellenállás.
A hozzászólás módosítva: Jan 29, 2013
(#) Kovabe válasza pjg hozzászólására (») Jan 29, 2013 /
 
Ok köszi most már felfogtam. Megint bele futottam, mert ugyebár mindig csak utolag kérdez az ember.
(#) n_yálastrubadúr hozzászólása Jan 29, 2013 1 /
 
Nagyon szépen kérném, ha valakinek van jobban optimalizáló hi-tech compliere, az legyen olyan kedves küldeje már el az incompatible@freemail.hu -ra. Nagyon szépen köszönöm. Nem teljesen ingyen kérném, de nagyon örülnék neki.
(#) tom75 válasza icserny hozzászólására (») Jan 29, 2013 /
 
De gondolom az számít mekkora feszültség kerül a bemenetre.
Szoftverbe kel beállítani, hogy mit jelezzen ki.
pl. ha 30 V a mérendő érték akkor nem mindegy, hogy 3 V-ra vagy 0,3V ra osztom le.
Ezt szoftverbe meg kell adni úgy e?
(#) icserny válasza tom75 hozzászólására (») Jan 29, 2013 /
 
Idézet:
„Ezt szoftverbe meg kell adni ugye?”
Természetesen.
(#) mykymokus hozzászólása Jan 29, 2013 /
 
Sziasztok kis segítséget kérnék. Assembly-ben PIC16f84A-ba. Táblázatból olvasok be adatokat 27h-ba Növelem 1el hogy a következő sort olvassa a táblázatból.Eddig rendbenm is van müxik rendesen de ha eléri a 255 lenulláz s kezdi előről.Hogy tudnám kibővíteni hogy tovább olvasson ?
  1. Table1  
  2.         ADDWF 02h,1   ;Start
  3.         RETLW 00h
  4.         RETLW 7Fh  
  5.         .
  6.         .
  7.         RETLW 0ffh    ; Táblázat vége
  8. Run1
  9.         CLRF 08h       ;törlés 8-25h-ig
  10.         .
  11.         .
  12.         CLRF 25h
  13.  
  14.         MOVLW 00       ; W-be tölt 0-át nullázza 27-et      
  15.         MOVWF 27h      ; W tartalmát mozgatja 27h-ba 27h=0
  16.  
  17. Run2
  18.         MOVLW 08h      ; 08 at mozgat W-be
  19.         MOVWF 30h      ; W tartalmát mozgatja 30h-ba 30h=08  Sebesség.
  20.         CALL Shift         ; Meghívja shift -et
  21.         INCF 27h,1       ; 1el növeli 27h tartalmát eredmény f-be kerül
  22.         MOVF 27h,0      ; 27h f regiszter tartalmának másolása W-be
  23.         CALL Table1      ; Meghívja a táblázat soronkövetkező adatát
  24.         MOVWF 25h      ; Beolvasott tábla adatot 25H-ba tölti
  25.         XORLW 0FFh     ; EZT NEM ÉRTEM !!! ha 0FFh talál a táblázatban kezdi előről?
  26.         BTFSC 03,2       ; bit 2 of file 3 will be SET (=1)  Ezt sem értem !!!
  27.         GOTO Run1       ; Run 1 - re ugrás
  28.  
  29. Run3    DECFSZ 30h,1  
  30.           GOTO Run4
  31.           GOTO Run2
  32. Run4    CALL Scan


Köszönöm
A hozzászólás módosítva: Jan 29, 2013
(#) icserny válasza mykymokus hozzászólására (») Jan 29, 2013 /
 
Idézet:
„Hogy tudnám kibővíteni hogy tovább olvasson ?”

Itt a segítség (4. oldal vége, Táblázatkezelés)
A hozzászólás módosítva: Jan 29, 2013
(#) mykymokus válasza icserny hozzászólására (») Jan 29, 2013 /
 
Köszönöm olvasom de nem nagyon értem.
(#) icserny válasza mykymokus hozzászólására (») Jan 29, 2013 /
 
Kettőnk között az a különbség, hogy én nem is akarom megérteni, csak kikerestem neked.
(#) mykymokus válasza icserny hozzászólására (») Jan 29, 2013 /
 
Köszönöm kedvességed azt hittem kened vágod
(#) Szamy hozzászólása Jan 30, 2013 /
 
Üdvözletek!
Két pic -et beszéltetnék egymással, rs232-n. Kell felhúzó ellenállást tennem ?
(#) zolek hozzászólása Jan 30, 2013 /
 
Üdv mindenkinek! Hp41C végre hajtottam amit ajánlottál, kicseréltem arra amit meg adtál de így sem működik. Nézd már meg ezt a kapcsolási rajzot hogy jó -e.
(#) Hp41C válasza zolek hozzászólására (») Jan 30, 2013 /
 
Szia!
A kapcsolás jónak tűnik, az oldalról letöltött program a szimulátorban fut. A tiedet nem tudom fordítani, mert nincs meg minden állomány hozzá.

fut.JPG
    
(#) zolek hozzászólása Jan 30, 2013 /
 
A PICkit2-vel két 16F628A-at programoztam , ebből csak az 1-et sikerült a másikat nem , azt csak felismeri .Mind kettőbe ugyan az a program lett volna. Próbáltam másik programmal is de az eredmény ugyan az. Ha valakinek volt ilyen segítsen.
(#) zolek válasza Hp41C hozzászólására (») Jan 30, 2013 /
 
Üdv Hp41C! Köszönöm a fáradozásodat
(#) mhatalyak hozzászólása Jan 30, 2013 /
 
Üdv mindenkinek!

.c kiterjesztésű fájlt hogyan tudom beégetni?

Előre is köszönöm a segítséget!
mhatalyak
(#) kistee válasza mhatalyak hozzászólására (») Jan 30, 2013 /
 
Szia,

Röviden: sehogy. Ugyanis az C nyelvű forráskód.
Bővebben: fordítás után .hex fájl lesz belőle, azt már be lehet égetni.

Üdv: t
(#) mhatalyak válasza kistee hozzászólására (») Jan 30, 2013 /
 
Igen, de nem bírom lefordítani HEX-re, esetleg, ha fel töltöm ide, valaki meg tudja nekem csinálni?
(#) llaczo hozzászólása Jan 30, 2013 /
 
Sziasztok. Van néhány bontott ( de tuti jó ) 18F452 I-/pt PICkem. JDM programozóval, WinPic800 as progi felismeri de semmi több. Mit gondoltok le vannak védve az ICk vagy kell szereznem egy komolyabb programozót? Köszi a választ. Üdv
(#) Hp41C válasza llaczo hozzászólására (») Jan 30, 2013 /
 
Egy teljes törléssel el lehet dönteni. A törlés után ki lehet olvasni a 0xFFFF tartalmat a program memróriából, a0xFF -et az adatmemóriából.
(#) mhatalyak válasza mhatalyak hozzászólására (») Jan 31, 2013 /
 
Hát ilyen nincs, egyszerűen nem bírom lefordítani, még a "bevezetés a PIC ológiába" c. videót is megnéztem és az alapján követtem a sorrendet, de még az .asm-et sem tudom lefordítani HEX-re. Most már az MPLAB a PicKit2-t sem engedi kipipálni. Bemásolom a forráskódot, hátha valami hiba van benne, én sajnos nem értek hozzá, de a legjobb lenne ha valaki le tudná fordítani nekem HEX-re.
  1. ;----------------------------------------------------------------------;
  2. ; bike3.asm   Combines: Time , Dist, Av velocity, Inst Vel  
  3. ;             Fred Maher             1st March 2002  
  4. ;   BASIC BICYCLE  COMPUTER WITH THESE FUNCTIONS              
  5. ;----------------------------------------------------------------------;
  6.  
  7. ; 1          Trip Time    HRS:MIN:SEC
  8. ; 2          Trip Dist    000km 00m
  9. ; 3          Trip AvSpd   00.00km/hr
  10. ; 4          Speed        00.00km/hr    
  11.  
  12.  
  13.  
  14.  
  15.  
  16. ;---------------------------------------------------------------------              
  17. ;-------                 HEADER                ----------
  18. ;---------------------------------------------------------------------
  19.  
  20. ;                      LCD MESSAGES
  21. ; position at beginning of 1st line col 0  movlw H'80
  22. ; position at beginning of second line     movlw H'C0'
  23.      
  24.  
  25.      LIST P=16F84           ;  16F84 Runs at 4.096 MHz
  26.      INCLUDE "p16f84A.inc"
  27.      __CONFIG    _CP_OFF & _WDT_OFF & _XT_OSC & _PWRTE_ON  
  28.  
  29.      ERRORLEVEL -224        ;  suppress annoying message because of tris
  30.      ERRORLEVEL -302        ;  suppress message because of page change
  31.  
  32. ; Define Information
  33.     #DEFINE RS PORTA, 2
  34.     #DEFINE E  PORTA, 3
  35.    ;#DEFINE TOGGLESW PORTB, 6  ; not used at the moment
  36.    ;#DEFINE LED PORTB, 5
  37. ;  Macro
  38.  
  39. ;---------------------------------------------------------------
  40.            CBLOCK     0CH   ;  0C to 4F = 67
  41. ;---------------------------------------------------------------
  42.  
  43. ;                   MATH ROUTINES    
  44.  
  45. ;                16 X16 Mult , --> 32
  46. ;     mah mal x mbh mbl = mq4 mq3 mq2 mq1 ( mq4 highest)
  47. mq4
  48. mq3
  49. mq2
  50. mq1        
  51. mbh
  52. mbl
  53. mah
  54. mal
  55. ;                   16 / 16 Div --> 16
  56. denlo          
  57.  denhi     
  58.  numlo           
  59.  numhi   
  60.  rmdrlo            
  61.  rmdrhi          
  62. reshi
  63. reslo
  64. ;temp       also used in nybble
  65.  
  66. ; Addition 16+16 out max 65536 (no carry)
  67. ; Subtraction q1_16-q2_16 out r_16; neg numbers not allowed
  68.          
  69.  q1hi                  
  70.  q1lo            
  71.  q2hi                            
  72.  q2lo            
  73.  rhi             
  74.  rlo             
  75. ;------------    Distance         -----------------------
  76.  
  77. dtotlo       ; total trip distance in metres
  78.  dtothi           ; dtothi/lo hold a max of 65km 536m,  
  79. dtothi2      ; with this added max now 16777km
  80. dist54       ; corrects +2m every 54m (27x2.0747 =56)
  81. dm
  82. dm10
  83. dm100
  84. dm1000
  85. dm10000
  86. dm100000
  87.  
  88. ;------------   Average velocity Vav    -------------------
  89.  
  90. ;vavhi
  91. ;vavlo
  92. ;divrat
  93. ;stemphi     ;second info passed to stemphi/lo
  94. ;stemplo    
  95.  ;dtemphi     ;dist info passed to dtemphi/lo  
  96. ;dtemplo
  97. m
  98. m10
  99. m100
  100. m1000
  101. ;---------   Time and trip time        --------------------
  102. ;
  103. sectotlo        ; total trip seconds
  104. sectothi        ; max 65536 = aprox 18hrs  
  105. sec             ; seconds digit
  106. sec10           ; 10's of second digit
  107.  min             ; minutes digit
  108.  min10           ; 10's of minutes digit
  109. hr              ; hours digit
  110. hr10            ; 10's of hours digit
  111.  oldsec          ; holds last value of sec
  112.  cntmsec         ; count ms
  113.  TMR18           ; TMR0 217* TMR18 18 = 1 SEC
  114.  
  115. ;----        isr interrupt service routine push pop  -------
  116.  w_temp          ; W isr var
  117.  status_temp     ; STATUS isr var
  118.  fsr_temp        ; FSR isr var
  119.  
  120.  
  121. ; ---------  Instantaneous Velocity  Vin  --------------------
  122.  vinhi
  123.  vinlo
  124.  sectemp
  125.  oldtemp
  126.  totmslo
  127.  totmshi
  128.  totms2lo
  129.  totms2hi
  130.  mshi
  131.  mslo
  132.  spdflg   ; 1st pass =0 2nd pass =1, diff is time between pulses
  133.  
  134.  
  135.  
  136. ;--------         Miscellaneous     ------------------
  137.  temp            ; a temporary used in divide and nybble
  138.  count
  139.  menu
  140.  
  141.  
  142.  
  143.        ENDC     ; end of definition block
  144. ;-------------------------------------------------------------------
  145.  
  146.          
  147.    ORG 0        ; start at location 0
  148.    goto main    ; jump over to main routine      
  149.    ORG 4
  150.    goto Isr     ; jump to interrupt routine
  151.  
  152.  
  153. ;----------------------------------------------------------------------;
  154. ;                           The Main routine                           ;
  155. ;----------------------------------------------------------------------;
  156.  
  157. ; --------       THE   MAIN MODULES    ---------
  158.  
  159.       ;  Isr       stores elapsed TRIP time and generates hr:min:sec
  160.       ;  Disptime  TRIP time, to max 99:59:59
  161.       ;  Dist      Calculates total TRIP distance
  162.       ;  Dispdist  TRIP distance to a max of 999km 999m
  163.       ;  Velav     Average velocity, Totdist/totsecs max 99km/hr
  164.       ;  Dispvav   Average TRIP speed up to  99.99 km/hr
  165.       ;  Velocity  Speed   2m/(time diff of pulse2-pulse1)
  166.       ;  Dispd     Speed  up to 99.99km/hr
  167.        
  168. ; NOTE. Speed is your  calculated velocity  every second
  169.        
  170. ; --------    more to come??? NO, running out of space         ---------
  171.  
  172.  
  173. ;-----------------------------------------------------------------------
  174. ;                           M A I N
  175. ;-----------------------------------------------------------------------
  176.  
  177.  
  178. main:
  179.        call Init               ; Initialize ports, set up timer
  180.        call Initlcd          ; Initialize the LCD DUMMY
  181.  
  182.  
  183. Initend:    
  184.  
  185.  
  186. ;------------------------------------------------------------------
  187. ; Changesec Changewhlpulse wait for interrupts  newsec or newwheelpulse
  188. ; -----------------------------------------------------------------
  189.  
  190.         clrf menu   ; initially set to 0 menu loop
  191.         clrf spdflg  ; Initially = 0 2nd =  sub for time  zero
  192.                          ; every new sec, set to zero
  193.  
  194. ;              CHANGESEC  LOOPS TILL SEC CHANGES  
  195.    
  196.       ;clrw                          ;DUMMY
  197.       ;xorwf sec,w              ;DUMMY
  198.       ;btfsc STATUS,2       ;DUMMY
  199.       ;incf sec,f               ;DUMMY
  200.  
  201. Changesec:               ;loops checking new sec and new wheel pulse
  202.      movf  oldsec, w
  203.      xorwf sec,w    
  204.                   ; if equal, w= 0 and Z bit=1
  205.     btfsc STATUS,2    ; test Z bit
  206.     goto  Changesec  ; no change, loop
  207.     movf  sec,w          ; sec has  increased, update
  208.     movwf oldsec       ; sec and oldsec are = again
  209.     incf  menu,f          ; increases menu every sec
  210.                  
  211.  
  212.             ; Note1, sectotlo/hi are updated every sec in ISR module
  213.             ; Note2, Decimal time also created in ISR module
  214.                              ; but time display for LCD  controlled
  215.                              ; the automatic menu below
  216.          
  217.       call Disptime   ;TRIP time,  will appear on LCD top line
  218.  
  219. Changewhp:          ; 1st detected wheelpulse starts menu sequence                
  220.                                    
  221.       clrf PORTB
  222.       bcf PORTB,5   ; start with green LED off
  223. loop:
  224.       btfss PORTB, 4  ;(PUT BTFSC FOR TEST); i/p hi,?DUMMY
  225.       goto loop            ; not yet
  226.                                  ; i/p hi detected
  227.                  ;green LED flashes with every wheel pulse    
  228.       bsf PORTB, 5    ; LED on
  229.                                 ; wait a while to make sure switch has
  230.                                 ; settled  
  231.       movlw D'10'      ; wait about 10 msec
  232.       call nmsec
  233.          
  234.       btfsc PORTB, 4  ; will be lo (0) when finished
  235.       goto $ -1            ; still low
  236.                                 ; now must wait a make sure bouncing stopped
  237.       movlw D'10'       ; 10 milliseconds
  238.       call nmsec
  239.                                 ; and check again
  240.       btfsc PORTB, 4 ; if set, not finished
  241.       goto $ -5            ; still hi start debounce  wait again
  242. Tp1:                         ; green LED ready for next wheel pulse
  243.       bcf PORTB,5        ; i.e. LED off
  244.       movf PORTB,w  ; reading to clear
  245.        
  246.  
  247.                                        
  248. ;              AUTOMATIC MENU: (LCD Top line always time)  
  249. ;              --------------
  250.                 ; menu s at 10sec intervals in rotation
  251.                 ; Speed            menu  1 to 10
  252.                 ; Dist ance       menu 11 to 20
  253.                 ; Velav Avg vel menu 21 to 30
  254.          
  255.                           ; MENU 0 TO 10
  256.  
  257. ; as speed ( Speed) is stand alone, no sense in calculating it
  258. ; if it is not going to be displayed when menu is >10.
  259. ; BUT if SPEED AVERAGING IS TO BE USED,  kill off  the lines below that bypass
  260. ; the SPEED calc module
  261.  
  262. Menucheck:
  263.       movlw 0x0A          ;check menu > 10  (to meet >10 AND =<20)
  264.       subwf menu,w
  265.       btfss STATUS,C   ;compare with 10
  266.       goto $+2               ;menucount =< 10 not yet got to 11 jump to Speed
  267.       goto Distblk
  268.      
  269.       call Speed            ; Calculates instant speed,(time between pulses)
  270.       movlw 0x0A         ; DUMMY, was  movlw 0xA
  271.       subwf menu,w
  272.       btfss STATUS,C  ;compare with 10
  273.       call Spdflgcheck  ;menucount =< 10 ; also see 0-1 spdflg  
  274.       goto Distblk
  275.  
  276. Spdflgcheck:
  277.       clrw  
  278.       xorwf spdflg,w
  279.       btfsc STATUS,Z
  280.       call Dispd        ;menucount =< 10 AND  spdflg =1
  281.       Return
  282.  
  283. Distblk:
  284.       call Dist        ;menucount  > 10 skip Dispd update Dist
  285.  
  286.  
  287.                                   ; MENU 11 TO 20
  288.       movlw 0x0A       ;check menu > 10  (to meet >10 AND =<20)
  289.       subwf menu,w
  290.       btfss STATUS,C   ;compare with 10
  291.       goto $+5         ;menucount =< 10 not yet got to 11 jump to velav
  292.       movlw 0x14
  293.       subwf menu,w
  294.       btfss STATUS,C   ;compare with 20
  295.       call Dispdist    ;menucount =< 20  
  296.       call Velav       ;menucount  > 20 skip dispdist update  Velav
  297.  
  298.  
  299.                           ; MENU 20 TO 30
  300.       movlw 0x14         ;check menu > 20  (to meet >20 AND =<30)
  301.       subwf menu,w
  302.       btfss STATUS,C  ;compare with 20
  303.       goto $+5             ;menucount =< 20 not yet got to 21 jump to NEXT
  304.       movlw 0x1E
  305.       subwf menu,w
  306.       btfss STATUS,C  ;compare with 30
  307.       call Dispvav         ;menucount =< 30
  308.       movlw 0x1F        ;if it has reached 31 reset menu, before return  
  309.       xorwf menu,w      
  310.       btfss STATUS,Z  
  311.       goto $ +2           ; not 31 goto changewhp1 direct
  312.       clrf menu           ; is 31, reset menu before changewhp1
  313.  
  314. Menuend:
  315.                                ; before changewhp jump, check that sec has not updated
  316.                                ; if it has , jump back to changesec routine
  317.       movf  oldsec, w
  318.       xorwf sec,w          ; if equal, w= 0 and Z bit=1
  319.       btfsc STATUS,2   ; test Z bit
  320.       goto  Changewhp ; no sec change, check whpulse change
  321.       goto  Changesec  ; a new sec starts measurements  
  322.  
  323.                                    ; loop while NOT newsec
  324. ; ---------------------------------------------------------------
  325. ;                          End Main
  326. ; ----------------------------------------------------------------
  327.  
  328.    
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335. ;----------------------------------------------------------------------;
  336. ; ISR, increments TMR0 by 1 every 256 ľsec. Basically just             ;
  337. ; reset the INTCON and TMR0 bits. The FSR,w, STATUS push pop kept      ;
  338. ;----------------------------------------------------------------------;
  339. Isr:
  340.             movwf w_temp             ; save W
  341.             swapf STATUS,W        ; save status
  342.             movwf status_temp      ; without changing flags
  343.             swapf FSR,W               ; save FSR
  344.             movwf fsr_temp           ; without changing flags
  345.  
  346.                                      ;256us * 217 * 18 = 0.999936 sec.  
  347.                                      ;1hr_err = 0.23sec or 1 sec in 4hr
  348.  
  349.   ;The time loop starts  with TMR0 loaded with  (256-217)=39 After 217
  350.   ;steps interrupt is set, TMR0 rolls to zero and the TMR18 inc +1  
  351.  
  352.             movlw D'39'           ;39 = 0x27
  353.             movwf TMR0
  354.             incf  TMR18,f
  355.             movlw D'18'          ; DUMMY18 = 0x12
  356.             xorwf TMR18,w    ; if equal, w= 0 and Z bit=1
  357.             btfss STATUS,2   ; test Z bit
  358.             goto  restore        ; NOT 18 so pop stack and return to main
  359. Firstsec:
  360.             clrf  TMR18          ; is 18. set TMR18 to zero and INC sec            
  361.             incf  sec,f             ; also inc sectot (eventually lo and hi)
  362.  
  363.             incf  sectotlo,f      ; check sectot lo 00->inc hi
  364.             clrw
  365.            xorwf sectotlo,w   ; if equal, w= 0 and Z bit=1
  366.             btfsc STATUS,2
  367.             incf sectothi,f      ; increases every 256 x sectotlo
  368.  
  369.             movlw 0xA          ; check if =10
  370.            xorwf sec,w          ; if equal, w= 0 and Z bit=1
  371.            btfss STATUS,2   ; test Z bit
  372.            goto  restore        ; NOT 10 so pop stack and return to main
  373.  
  374.             clrf sec               ; is 10. set sec to zero and inc sec10
  375.             incf sec10,f        
  376.             movlw 0x6         ; = 0x6
  377.             xorwf sec10,w   ; if equal, w= 0 and Z bit=1
  378.             btfss STATUS,2  ; test Z bit
  379.             goto  restore      ; NOT 6 so pop stack and return to main
  380.  
  381.  
  382.             clrf  sec10         ; is 6. set sec10  to zero and INC min            
  383.             incf  min,f
  384.             movlw 0xA       ; check if =10
  385.             xorwf min,w     ; if equal, w= 0 and Z bit=1
  386.             btfss STATUS,2  ; test Z bit
  387.             goto  restore        ; NOT 10 so pop stack and return to main
  388.  
  389.             clrf min                ; is 10. set sec to zero and inc min10
  390.             incf min10,f        
  391.             movlw 0x6          ;= 0x6
  392.            xorwf min10,w     ; if equal, w= 0 and Z bit=1
  393.            btfss STATUS,2  ; test Z bit
  394.             goto  restore      ; NOT 6 so pop stack and return to main
  395.  
  396.             clrf  min10         ; is 6. set min10  to zero and INC hr            
  397.             incf  hr,f
  398.             movlw 0xA        ;check if =10
  399.             xorwf hr,w         ; if equal, w= 0 and Z bit=1
  400.             btfss STATUS,2  ; test Z bit
  401.             goto  restore       ; NOT 10 so pop stack and return to main
  402.  
  403.             clrf hr                   ; is 10. set hr to zero and inc hr10
  404.             incf hr10,f        
  405.             movlw 0xA          ;= 10
  406.             xorwf hr10,w       ; if equal, w= 0 and Z bit=1
  407.            btfss STATUS,2  ; test Z bit
  408.             goto  restore      ; NOT 10 so pop stack and return to main  
  409.  
  410.                              
  411.                              
  412.             clrf sec              ; is ten (99hr 59min 59sec +1sec) we are at MAX
  413.             clrf sec10          ;all reset to zero and start again
  414.             clrf min
  415.             clrf min10
  416.             clrf hr
  417.             clrf hr10
  418.             clrf TMR18
  419.             clrf oldsec
  420.             goto restore
  421.  
  422. restore:
  423.             swapf status_temp,W      ; get original status back
  424.             movwf STATUS             ; into status register
  425.             swapf fsr_temp,W         ; get original fsr back
  426.             movwf FSR                  ; into status register
  427.             swapf w_temp,f           ; old no flags trick again
  428.             swapf w_temp,W         ; to restore W
  429.             bcf INTCON,T0IF        ; clear the TMR0 interrupt flag
  430.             retfie                           ; finished, reset GIE
  431.  
  432. ;----------------------------------------------------------------------;
  433. ;                       Initialize the ports                           ;
  434. ;----------------------------------------------------------------------;
  435. Init:
  436.             clrf   PORTA
  437.             clrf   PORTB
  438.  
  439.             movlw B'00000000'          ;  Porta all outputs
  440.             tris PORTA
  441.  
  442.             movlw B'01010000'          ; 7o 6i-Wire 5o-LED 4i-multivib,
  443.             tris PORTB                     ; 0to3lcd
  444.  
  445.  
  446.             movlw B'00000111'          ;  opt pull-ups enabled                                    
  447.                                                      ;  opt prescaler assigned to TMR18
  448.                                                      ;  opt prescaler set to 1:256
  449.             option                               ;  opt rolls over each 125th second
  450.                            
  451.  
  452.  movlw 0                                       ;  zero out all registers
  453.  
  454.    
  455.  clrf m
  456.  clrf m10
  457.  clrf m100
  458.  clrf m1000
  459.  clrf dm
  460.  clrf dm10
  461.  clrf dm100
  462.  clrf dm1000
  463.  clrf dm10000
  464.  clrf dm100000
  465.  
  466.  clrf totmshi
  467.  clrf totmslo
  468.  clrf totms2hi
  469.  clrf totms2lo
  470.  clrf dist54
  471.  
  472.            
  473.  clrf hr10
  474.  clrf hr
  475.  clrf min10                
  476.  clrf min
  477.  clrf oldsec
  478.  clrf sec10
  479.  clrf sec
  480.  clrf sectotlo
  481.  clrf dtotlo
  482.  clrf dtothi
  483.  clrf sectotlo
  484.  clrf sectothi
  485.  clrf TMR18   ; when this reaches 18, 1 sec has elapsed        
  486.            
  487.    
  488.             ; TMR0 has to start at 256-217 :39, so that the first rollover
  489.             ; with prescaler 256, happens in 217*256us =0.055552sec
  490.             ; The TMR18 incs each roll and after 18  1 sec has elapsed
  491.             movlw 0x27       ; D39  
  492.             movwf TMR0    ; set to D39 217 counts later 256,
  493.                                      ; TMR0 resets and inc TMR18 in Isr loop
  494.  
  495.            clrf  INTCON      ; START WITH ALL AT 0
  496.        
  497.                                   ; movlw B'10100000'          ; GIE set T0IE set, T0IF cleared
  498.           movlw B'10100000' ; Set:GIE,T0IE,RBIE Clrd:T0IF,RBIF
  499.           movwf INTCON      ; ready to detect interrupts in ISR
  500.           return
  501.  
  502. ;----------------------------------------------------------------------;
  503. ;                 Initialize the LCD                                   ;
  504. ;----------------------------------------------------------------------;
  505. Initlcd:
  506.   movlw D'40'
  507.   call   nmsec                  ;  Wait 40 msecs before Reset
  508.   bcf    RS                       ;  send an 8 bit instruction
  509.   movlw  0x03                 ;  Reset Command
  510.  
  511.   call   NybbleOut          ;  Send the Nybble
  512.   call   Dlay5                  ;  Wait 5 msecs before Sending Again
  513.  
  514.   call EStrobe
  515.   call Dlay160                ;  Wait 160 usecs before Sending 2nd Time
  516.   call EStrobe
  517.   call Dlay160                ;  Wait 160 usecs before Sending 3rd Time
  518.   bcf    RS                     ;  send an 8 bit instruction
  519.   movlw  0x02               ;  Set 4 Bit Mode
  520.  
  521.   call   NybbleOut              
  522.   call Dlay160
  523.   movlw  0x028                  ;  4 bit, 2 Line, 5x7 font
  524.   call   SendINS
  525.   movlw  0x010                  ;  display shift off
  526.   call   SendINS
  527.   movlw  0x001                  ;  Clear the Display RAM
  528.   call   SendINS
  529.   call   Dlay5                      ;  Note, Can take up to 4.1 msecs
  530.   movlw  0x006                  ;  increment cursor
  531.   call   SendINS
  532.   movlw  0x00C                 ;  display on cursor off
  533.   call   SendINS
  534.   return
  535.  
  536. ;----------------------------------------------------------------------;
  537. ;              Send the character in W out to the LCD                  ;
  538. ;----------------------------------------------------------------------;
  539. SendASCII
  540.   addlw '0'                     ;  Send nbr as ASCII character
  541.  
  542. SendCHAR:                  ;  Send the Character to the LCD
  543.   movwf  temp               ;  Save the temporary Value
  544.   swapf  temp, w           ;  Send the High Nybble
  545.   bsf    RS                     ;  RS = 1
  546.   call   NybbleOut
  547.   movf   temp, w            ;  Send the Low Nybble
  548.   bsf    RS
  549.   call   NybbleOut
  550.   return
  551.  
  552. ;-------------------------------------------------------------
  553. ;              ES strobe
  554. ;-------------------------------------------------------------
  555. EStrobe:                ;  Strobe the "E" Bit
  556.  
  557.   bsf    E
  558.   bcf    E
  559.   return
  560. ;----------------------------------------------------------------------;
  561. ;              Send an instruction in W out to the LCD                 ;
  562. ;----------------------------------------------------------------------;
  563. SendINS:                  ;  Send the Instruction to the LCD
  564.   movwf  temp           ;  Save w
  565.   swapf  temp, w       ;  send Hi Nybble
  566.   bcf    RS                 ;  RS to 0
  567.   call   NybbleOut
  568.   movf   temp, w        ;  Send Lo Nybble
  569.   bcf    RS
  570.   call   NybbleOut
  571.   return
  572.  
  573. ;----------------------------------------------------------------------;
  574. ;              Send the nibble in W out to the LCD                     ;
  575. ;----------------------------------------------------------------------;
  576. NybbleOut:              ;  Send a Nybble to the LCD
  577.   movwf  PORTB        
  578.   call EStrobe          ;  Strobe out the LCD Data
  579.   bsf    E
  580.   call Dlay160          ;  delay for 160 usec
  581.   return
  582.  
  583. ;----------------------------------------------------------------------;
  584. ;                   Output the message on the LCD                      ;
  585. ;----------------------------------------------------------------------;
  586. OutMessage1:
  587.   movwf  FSR                    ;  Point at first letter
  588. OutLoop:
  589.   movf   FSR, w                 ;  Get pointer into W
  590.   incf   FSR, f                     ;  Set up for next letter
  591.   call   Dispmsg1               ;  Get character to output
  592.   iorlw  0                            ;  At the End of the Message?
  593.   btfsc  STATUS, Z            ;  Skip if not at end
  594.   return                              ;  Yes - Equal to Zero
  595.   call   SendCHAR             ;  Output the ASCII Character
  596.   goto   OutLoop                ;  Get the next character
  597.  
  598. ;----------------------------------------------------------------------;
  599. ;                    Data for message to be output                     ;
  600. ;----------------------------------------------------------------------;
  601. Dispmsg1:                         ;  Message to Output
  602.   addwf  PCL, f                  ;  Output the Characters
  603.   dt     "Bike Computer", 0
  604.  
  605. Dispmsg2:                       ;  Message to Output
  606.   addwf  PCL, f                 ;  Output the Characters
  607.   dt     "Dist", 0  
  608.  
  609. Dispmsg3:
  610.   addwf PCL,f                 ; message to output
  611.   dt     " Av speed:",0      ; output characters
  612.  
  613.  ;----------------------------------------------------------------------;
  614.  ;                        time delay routines                           ;
  615.  ;----------------------------------------------------------------------;
  616. ;Note . The original application needed precise times  the  delay code that
  617.  ; follows. But the Simple  Bike application does NOT use the routines for
  618.  ; any CRITICAL time measurement.
  619.  
  620. Dlay160:    
  621.   movlw D'41'                ;  delay about 160 usec
  622.  
  623. micro4:    
  624.  addlw H'FF'                ;  subtract 1  'W'
  625.  btfss STATUS,Z         ;  skip when you reach zero
  626.  goto micro4                ;  more loops
  627.  return                    
  628.  
  629. Dlay5:      
  630.  movlw 5                     ;  delay for 5 milliseconds    
  631.  goto $ + 2
  632. msec250:    
  633.  movlw D'250'              ; delay for 250 milliseconds
  634.  
  635.                             ; --- N millisecond delay routine ---
  636. nmsec:      
  637.  movwf cntmsec            ; delay for N (you put in W) millisec
  638. msecloop:  
  639.  movlw D'254'               ; load takes .9765625 microsec
  640.  call micro4                  ; by itself CALL takes ...
  641.                                     ; about 1ms
  642.                                        
  643.  nop                             ; 1usec
  644.  decfsz cntmsec, f       ; .98 skip not taken, else 1.95
  645.  goto msecloop           ; 1.95 here: total ~1000 / loop
  646.  return                         ; final time through ~999 to here
  647.                                    ; overhead in and out ignored
  648.  
  649.                                   ; this block is functional for tests, but not used in bike
  650. Dlay1sec:          ; this is a marker routine to see where
  651.  call msec250             ; the prg is at.
  652. ; bsf  LED
  653.  call msec250          ;flash led on portb pin6
  654. ;bcf  LED
  655.  call msec250
  656. ; bsf  LED
  657.  call msec250   ; finishes with green led lit
  658.  return
  659.  
  660. ;----------------------------------------------------------------------;
  661. ;                       Display the Time                               ;
  662. ;----------------------------------------------------------------------;
  663. Disptime:
  664.    
  665.  movlw H'80'        ;  position at beginning of first line
  666.  call SendINS
  667.  movf hr10, W      ;  tens of hours
  668.  call SendASCII
  669.  movf hr, W          ;  hours
  670.  call SendASCII
  671.  movlw ":"        
  672.  call SendCHAR
  673.  movf min10, W    ;  tens of minutes
  674.  call SendASCII
  675.  movf min, W        ;  minutes
  676.  call SendASCII
  677.  movlw ":"
  678.  call SendCHAR
  679.  movf sec10, W    ;  tens of seconds
  680.  call SendASCII
  681.  movf sec, W       ;  seconds
  682.  call SendASCII
  683.  movlw " "
  684.  call SendCHAR   ; the h m s really not needed
  685.  movlw "h"
  686.  call SendCHAR
  687.  movlw "m"
  688.  call SendCHAR
  689.  movlw "s"
  690.  call SendCHAR
  691.  movlw " "
  692.  call SendCHAR
  693.  
  694. Dispend:
  695.               RETURN
  696.  
  697. ;----------------------------------------------------
  698. ;               End of display time
  699. ;----------------------------------------------------
  700.  
  701.  
  702. ;----------------------------------------------------------------------;
  703. ;                    Display the Distance , (trip distance at moment)                               ;
  704. ;----------------------------------------------------------------------;
  705. Dispdist:      
  706.  movlw H'C0'       ;  position at beginning of second line
  707.  call SendINS
  708.  
  709.  movf dm100000, W     ;  0 of 065km 536m
  710.  call SendASCII
  711.  
  712.  movf dm10000, W      ;  6 of 065km 536m
  713.  call SendASCII
  714.  
  715.  
  716.  movf dm1000, W       ;  5 of 065km 536m
  717.  call SendASCII
  718.  
  719.  movlw "k"                 ;  k of 065km 536m
  720.  call SendCHAR
  721.  movlw "m"                ;  m of 065km 536m
  722.  call SendCHAR
  723.  movlw " "                  ;  " " of 065km 536m
  724.  call SendCHAR
  725.  
  726.  movf dm100,W         ;  5 of 065km 536m
  727.  call SendASCII
  728.  
  729.  movf dm10,W          ;  3 of 065km 536m
  730.  call SendASCII
  731.  movf dm, W             ;  6 of 065km 536m
  732.  call SendASCII
  733.              
  734.  movlw "m"               ;  m of 065km 536m    
  735.  call SendCHAR
  736.  
  737.  movlw " "                 ; " "  
  738.  call SendCHAR
  739.  movlw "D"               ; "D "  
  740.  call SendCHAR
  741.  movlw "i"                ; " i"  
  742.  call SendCHAR
  743.  movlw "s"               ; "s "  
  744.  call SendCHAR
  745.  movlw "t"                ; " t"  
  746.  call SendCHAR
  747.  movlw " "               ; " " ( to wipe screen)
  748.  call SendCHAR  
  749.  
  750. Distend:
  751.               RETURN
  752.  
  753.  
  754. ;
  755. ;---------------------------------------------------------------------*
  756. ;                Multiplication  16x16 Out32
  757. ;---------------------------------------------------------------------*
  758. Mult16x16:
  759.         clrf mq4
  760.         clrf mq3
  761.         clrf mq2
  762.         clrf mq1
  763.  
  764.  
  765.         bsf mq2, 7
  766. Mu1:
  767.         rrf mah, f
  768.         rrf mal, f
  769.         skpc
  770.         goto Mu2
  771.         movf mbl, w
  772.         addwf mq3, f
  773.         movf mbh, w
  774.         skpnc
  775.         incfsz mbh, w
  776.         addwf mq4, f
  777. Mu2:
  778.         rrf mq4, f
  779.         rrf mq3, f
  780.         rrf mq2, f
  781.         rrf mq1, f
  782.         skpc
  783.         goto Mu1
  784.  
  785. Endmult16:
  786.       clrf mbh
  787.       clrf mbl
  788.       clrf mah
  789.       clrf mal
  790.  
  791.         Return
  792.  
  793.  
  794.        
  795.  
  796. ;---------------------------------------------------------------------*
  797. ;            End Multiplication   16x16 Out32
  798. ;---------------------------------------------------------------------*
  799.  
  800. ;---------------------------------------------------------------------*
  801. ;       New routine Division  16/16 Out 16
  802. ; ---------------------------------------------------------------------*
  803. ; Finally:- Result 000AH in reshi/lo, remainder 0096H in rmdrhi/lo
  804. ; so, checking end of division A=10 and 96H/E1H= 150/225 =0.666  OK
  805.  
  806. Div:
  807.        call    D_divS          ; remainder in Rmdr.
  808. Divend:
  809.           nop
  810.           return
  811. D_divS:
  812.         call    setup
  813.         clrf    rmdrhi
  814.         clrf    rmdrlo
  815. dloop:
  816.       bcf     STATUS,C
  817.         rlf     reslo, f
  818.         rlf     reshi, f
  819.         rlf     rmdrlo, f
  820.         rlf     rmdrhi, f
  821.         movf    denhi,w
  822.         subwf   rmdrhi,w      ;check if a>c
  823.         btfss   STATUS,Z
  824.         goto    nochk
  825.         movf    denlo,w
  826.         subwf   rmdrlo,w      ;if msb equal then check lsb
  827. nochk:
  828.         btfss   STATUS,C    ;carry set if c>a
  829.         goto    nogo
  830.         movf    denlo,w        ;c-a into c
  831.         subwf   rmdrlo, f
  832.         btfss   STATUS,C
  833.         decf    rmdrhi, f
  834.         movf    denhi,w
  835.         subwf   rmdrhi, f
  836.         bsf     STATUS,C    ;shift a 1 into b (result)
  837. nogo:
  838.                 rlf     numlo,f
  839.         rlf     numhi,f
  840.         decfsz  temp, f        ;loop untill all bits checked
  841.         goto    dloop
  842.  
  843. setup:
  844.                 movlw   .16             ; for 16 shifts
  845.         movwf   temp
  846.         movf    numhi,w      ;move Num to Res
  847.         movwf   reshi
  848.         movf    numlo,w
  849.         movwf   reslo
  850.         clrf    numhi
  851.         clrf    numlo
  852.         retlw   0
  853.  
  854.  ;--------------------------End Div 16 by 16----------------------------
  855.  
  856.  
  857.  
  858.         return
  859.        
  860. ;---------------------------------------------------------------------*
  861. ; END DIVISION  16/16 OUT 16
  862. ;---------------------------------------------------------------
  863.  
  864. ;---------------------------------------------------------------------*
  865. ; START Addition  16-16 OUT 16
  866. ;---------------------------------------------------------------
  867. Add:  ; R = q1 + q2
  868.  
  869.         movf q1lo, W
  870.         addwf q2lo, W
  871.         movwf rlo
  872.  
  873.         movf q1hi, W
  874.         btfsc STATUS, C
  875.         addlw .1                ; If A Carry Occurred, Add 1
  876.  
  877.         addwf q2hi, W
  878.         movwf rhi
  879.         ;clrf q1hi                  ; added this to stop next user summing;
  880.         ;clrf q1lo
  881.         ;clrf q2hi
  882.         ;clrf q2lo
  883.        
  884.         Return
  885.  
  886. ;---------------------------------------------------------------------*
  887. ; END Addition  16-16 OUT 16
  888. ;---------------------------------------------------------------
  889.  
  890.  
  891.  
  892. ;---------------------------------------------------------------------*
  893. ; START Subtraction  16-16 OUT 16
  894. ;---------------------------------------------------------------
  895.  
  896.  
  897. Sub:    ; R = q1 - q2
  898.  
  899.         movf q2lo, W
  900.         subwf q1lo, W   ; W = q1lo - q2lo
  901.         movwf rlo
  902.  
  903.         btfss STATUS, C
  904.         Goto Borrow
  905.         Goto Sub1
  906. Borrow:
  907.         Decf q1hi, F
  908.        
  909. Sub1:
  910.         movf q2hi, W
  911.         subwf q1hi, W   ; W = q1hi - q2hi
  912.         movwf rhi
  913.  
  914.         Return
  915.  
  916. ;---------------------------------------------------------------
  917. ; END Subtraction  16-16 OUT 16
  918. ;---------------------------------------------------------------
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925. ;---------------------------------------------------------------
  926. ;                 Dist = counting wheel pulses
  927. ;---------------------------------------------------------------
  928.  
  929. Dist:                ; whlcirc = 2.0747, for initial test =2
  930.                       ;  
  931.                       ; movlw 0x2          ; <-- don't forget, this is just for 26"wheel
  932.                      ; movwf whlcirc  ; start count at 0 and inc till same as whlcirc
  933.                      ; (range will be 1 to 4 m)
  934.  
  935.          clrf count     ;  count can be 2 or 4 in this 26" case
  936.  
  937. Whloop:            ; although the distance pulses ( in this example) jump in steps of 2m
  938.                         ; the m counter has to increase in 1's to catch the
  939.                  ; decimal rollover  10 to 0
  940.                          ; so count, here, is stepped  0 to 2 (whlcirc)
  941.                          ; Also, when the dist54 var increases 54m, COUNT adds an  extra 2m  
  942.                          ; to the hex and decimal totals, before resetting to zero.
  943.                 ; Note that as dist54 is in the loop it will also receive
  944.                  ; the 2m increase so it  really  counts to 56 (54 +2).
  945.  
  946.  
  947.        movlw 0x2               ; wheel circumference  of 26 inch
  948.        xorwf count,w          ; if equal, w= 0 and Z bit=1
  949.        btfsc STATUS,2      ; test Z bit
  950.        goto DistanceEnd    ; they are the same, so jump distanceEnd and return  
  951.        goto Mcount            ; NOT  yet = whlcirc, so inc mcount by 1 and  return  
  952.  
  953. Mcount:       ; Distance to decimal for display , i/p m, o/p 000km 000m
  954.             ; starts  with m, m10, m100, m1000 , m10000, m100000 = 0
  955.             ; Later correct m every 54m (add 2m ???? )
  956.  
  957.       incf dm,f
  958.       movlw D'10'      
  959.       xorwf dm,w           ; if equal, w= 0 and Z bit=1
  960.       btfss STATUS,2   ; test Z bit
  961.       goto Mcountend   ; NOT 0 so return
  962.  
  963.       clrf dm
  964.       incf dm10,f
  965.       movlw D'10'    
  966.       xorwf dm10,w      ; if equal, w= 0 and Z bit=1
  967.       btfss STATUS,2   ; test Z bit
  968.       goto Mcountend   ; NOT 0 so return
  969.  
  970.       clrf dm10
  971.       incf dm100,f
  972.       movlw D'10'      
  973.       xorwf dm100,w     ; if equal, w= 0 and Z bit=1
  974.       btfss STATUS,2   ; test Z bit
  975.       goto Mcountend   ; NOT 0 so return
  976.  
  977.       clrf dm100
  978.     incf dm1000,f
  979.       movlw D'10'        
  980.       xorwf dm1000,w    ; if equal, w= 0 and Z bit=1
  981.       btfss STATUS,2   ; test Z bit
  982.       goto Mcountend   ; NOT 0 so return
  983.  
  984.       clrf dm1000
  985.       incf dm10000,f
  986.       movlw D'10'      
  987.       xorwf dm10000,w   ; if equal, w= 0 and Z bit=1
  988.       btfss STATUS,2   ; test Z bit
  989.       goto Mcountend   ; NOT 0 so return
  990.      
  991.       clrf dm10000
  992.       incf dm100000,f
  993.       movlw D'10'        
  994.       xorwf dm100000,w  ; if equal, w= 0 and Z bit=1
  995.       btfss STATUS,2      ; test Z bit
  996.       goto Mcountend      ; NOT 0 so return
  997.       clrf dm                     ; is distmax, reset to 0     
  998.       clrf dm10
  999.       clrf dm100
  1000.       clrf dm1000
  1001.       clrf dm10000
  1002.       clrf dm100000
  1003.  
  1004.       goto Mcountend  ; see if whpl  update is now finished
  1005.  
  1006.  
  1007.  
  1008.          
  1009. Mcountend:  ;update the hex counters dtot /lo/hi/hi2
  1010.       incf dtotlo,f
  1011.       clrw
  1012.       xorwf dtotlo,w       ; if equal, w= 0 and Z bit=1
  1013.       btfss STATUS,2   ; test Z bit
  1014.       goto Dtotend        ; dtotlo NOT 0
  1015.       incf dtothi,f           ; add 1, dtotlo is 0
  1016.       clrw
  1017.       xorwf dtothi,w      ; if equal, w= 0 and Z bit=1
  1018.       btfss STATUS,2   ; test Z bit
  1019.       goto Dtotend        ; dtothi NOT 0
  1020.       incf dtothi2,f         ; add 1, dtothi is 0
  1021.  
  1022. Dtotend:
  1023.       movlw D'54'
  1024.       movwf numhi       ; not in use here, use to store 54
  1025.       movf  dist54,w                     
  1026.       subwf numhi,w
  1027.       btfsc STATUS,C      
  1028.       goto  Noextra      ; dist54=< 53, don't freeze COUNT
  1029.      movlw D'56'        ; dist54>53   add 2 extra counts
  1030.      movwf numhi      ; not in use here to store 56
  1031.       movf  dist54,w                     
  1032.      subwf numhi,w
  1033.      btfsc STATUS,C              
  1034.      goto  Extra          ; dist54=< 56, freeze COUNT
  1035.      clrf dist54
  1036.      goto Noextra
  1037.  
  1038.  
  1039.  
  1040. Noextra:
  1041.     incf dist54,f
  1042.     incf count,f
  1043.    goto Whloop
  1044.  
  1045. Extra:                          ; an extra loop BUT count is NOT increased
  1046.    incf dist54,f
  1047.   goto Whloop    
  1048.  
  1049. DistanceEnd:  ;  All conversion loops have executed and
  1050.                       ; only left to display in decimal, when ed
  1051.                   ;  
  1052.      
  1053.  return          ; BACK TO MAIN
  1054.  
  1055.  
  1056. ;--------------------------------------------------------------------------
  1057. ;              End of Trip  Distance calculation Module
  1058. ;--------------------------------------------------------------------------
  1059.  
  1060.  
  1061. ;----------------------------------------------------------  
  1062. ;     Calculate Average velocity  Velav = totdist/totsec                   
  1063. ;-----------------------------------------------------------
  1064. ; 1st time round distto = 0 and sectot =0.
  1065. ; Disttot lo/hi zero is prob OKbut test sec=0. If zero return
  1066. Velav:
  1067.  
  1068.          
  1069.     clrw
  1070.     xorwf sectotlo,w
  1071.     btfss STATUS,Z
  1072.     goto  Spdstart     ; not 0, onto Avspeed calc
  1073.      clrw                ; lo was 0, but hi byte may not be
  1074.     xorwf sectothi,w
  1075.     btfss STATUS,Z    
  1076.     goto  Spdstart     ; was not 0, onto Avspeed calc
  1077.      ;incf  sectotlo,f   ; DUMMY
  1078.      ;goto  Spdstart   ; DUMMY
  1079.       return             ; was also 0, abort module  wait for sec inc
  1080.  
  1081.                 ; to slow down the number of whpul in the test we add Dummies  
  1082. Spdstart:                 ; for test delay incf sec and sectot, gives 7.2km/hr
  1083.            
  1084.      
  1085.       ;incf  sec,f        ; DUMMY
  1086.      ;incf sectotlo,f      ; DUMMY
  1087.  
  1088.  
  1089. ;Lpstart:
  1090.       movlw 0x07                 ; 1800   comp hi bytes
  1091.      subwf dtothi,w
  1092.      btfsc STATUS,C      
  1093.      goto  Divratio      ;  dtothi is > 1800hi and needs dividing
  1094.                          ;  we suppose that the hibyte test is sufficient,
  1095.                  ;  it may not be true. e.g hi's the same but lo's diff
  1096.                                ;  pass dtot to m1000,m100
  1097.    movf dtothi,w        ; dtothi <1800
  1098.    movwf m1000
  1099.    movf dtotlo,w
  1100.    movwf m100         ; m1000,m100 hold dtothi/lo ( no div needed)
  1101.    movf  sectothi,w    
  1102.    movwf m10
  1103.    movf sectotlo,w
  1104.    movwf m             ; m10,m hold sectothi/lo ( no div needed)  
  1105.  
  1106.                        ; note, this is dtot to m1000,m100 not needing division
  1107.    goto  Ratend       ; if divratio is needed, then m1000,m100 is used there
  1108.  
  1109. Divratio:                   ; enter variables and 1800
  1110.  
  1111.      movf  dtothi,w
  1112.      movwf numhi
  1113.      movf  dtotlo,w
  1114.      movwf numlo
  1115.      movlw 0x07
  1116.      movwf denhi
  1117.      movlw 0x08
  1118.      movwf denlo
  1119.      call  Div
  1120.      incf  reslo,w    ; reslo holds INT of Divratio +1
  1121.      movwf count   ; not used at the moment
  1122.      movf  dtothi,w ; divide dtothi/lo by count
  1123.      movwf numhi
  1124.      movf  dtotlo,w
  1125.      movwf numlo
  1126.      clrf  denhi
  1127.      movf  count,w  ; e.g. D 37
  1128.      movwf denlo
  1129.      call  Div          ; we need parking space for results, REuse the m1000 etc
  1130.      movf  reshi,w  
  1131.      movwf m1000 ;
  1132.      movf  reslo,w
  1133.      movwf m100   ; m1000, m100 =dtot/count
  1134.                            ; repeat for sectot
  1135.      movf  sectothi,w
  1136.      movwf numhi
  1137.      movf  sectotlo,w
  1138.      movwf numlo
  1139.      clrf  denhi
  1140.      movf  count,w    ; e.g D 37
  1141.      movwf denlo
  1142.      call  Div
  1143.      movf  reshi,w
  1144.      movwf m10  
  1145.      movf  reslo,w
  1146.      movwf m         ; m10, m =sectot/count
  1147. Ratend:
  1148.  
  1149. ;    WE CAN NOW DO DTOT/SECTOT x3.6  as we have SCALED TO AVOID OVERFLOW
  1150.  
  1151. ;                m1000,m100   x 36   (top line)
  1152. ;     Vav=   -------------------------                      = Average speed in km/hr
  1153.  
  1154. ;               m10,m        x 10   (bottom line)         ;     36(24H), 10(AH)
  1155.  
  1156.  
  1157.  
  1158.      movf m1000,w     ; MULT dtot, top line,  by 24H
  1159.      movwf mah
  1160.      movf m100,w
  1161.      movwf mal
  1162.      clrf  mbh
  1163.      movlw 0x24
  1164.      movwf mbl
  1165.      call  Mult16x16  ; ( store top line result in the same variables)
  1166.      movf  mq2,w
  1167.      movwf m1000
  1168.      movf  mq1,w
  1169.      movwf m100    ;  dtot x 36
  1170.  
  1171.     movf m10,w      ; MULT sectot, bottom line,  by AH
  1172.     movwf mah
  1173.     movf m,w
  1174.     movwf mal
  1175.      clrf  mbh
  1176.      movlw 0xA
  1177.      movwf mbl
  1178.      call  Mult16x16 ; ( store bottom line result in the same variables)
  1179.      movf  mq2,w
  1180.      movwf m10
  1181.      movf  mq1,w
  1182.      movwf m         ;  sectot x 10
  1183. Tp3:
  1184.  
  1185.       ; As we are reusing variables, trying to show where the results to here are being held
  1186.  ;                                      m1000,m100     
  1187. ;   We now have as  Average speed     ----- ---------       km/hr
  1188. ;                                                              m10,m
  1189.  
  1190.  
  1191.   ;the AVERAGE SPEED AT LAST
  1192.  
  1193.      movf  m1000,w  ; dtotx36/sectotx10
  1194.      movwf numhi
  1195.      movf  m100,w  
  1196.      movwf numlo
  1197.      movf  m10,w
  1198.      movwf denhi    ; needed below for decimal place
  1199.     movf  m,w
  1200.     movwf denlo    ; needed below for decimal place
  1201.     call  Div
  1202.                             ; denhi/lo can chanfge as the div routine reuses bits
  1203.                     ; so we reestablish previous denom values before losing
  1204.    movf  m10,w
  1205.    movwf denhi
  1206.    movf  m,w
  1207.    movwf denlo   ; we can now write over m and m10  
  1208.                        
  1209.    movf  reshi,w  ;will be zero
  1210.                    ;(bikes don't exceed 256km/hr normally)
  1211.     movf  reslo,w  ; reuse variables m10 INT and later m FRAC
  1212.     movwf m10     ;we have integer part of Vav Average speed
  1213.                    
  1214.    
  1215.  
  1216.                          ; rmdrhi/lo holds decimal fraction.we will only use 1 decimal place.  
  1217.                 ; so mult the rmdrhi,lo x10  before dividing by denhi/lo
  1218.        
  1219.  
  1220.   movf  rmdrhi,w     ; mult top by 10
  1221.   movwf mah
  1222.   movf  rmdrlo,w
  1223.   movwf mal           ; rmdr in tot storage
  1224.   clrf  mbh
  1225.   movlw 0xA
  1226.   movwf mbl
  1227.   call  Mult16x16  ; rmdrhi,lo x 10
  1228.                             ; top line is now  mq2,mq1 ( nothing in mq4,mq3)  
  1229.                             ; Bottom line..remember we already have loaded
  1230.                            ; the denominator above which says  
  1231.                             ; " needed below for decimal place"  
  1232. Tp4:
  1233. movf mq2,w       ;rmdrhi,w      
  1234.     movwf numhi
  1235.     movf  mq1,w        ;rmdrlo,w    
  1236.     movwf numlo      
  1237.     call Div                ; div for the decimal( just 1 place), in reslo
  1238.                 ; reshi,reslo holds decimal place results
  1239.                                 ; m10+m are  av speed as INT+DEC but in hex
  1240.                                ; now change to decimal.
  1241.                                ; m10 and m are going to be wiped, but there is no
  1242.                                ;divide routine so for INT +FRAC we use reshi reslo
  1243.       movf  m10,w
  1244.       movwf reshi      ; OK? yes reshi +reslo = INT+FRAC in hex, convert         
  1245.        
  1246.  
  1247. Vavh2d:
  1248.  
  1249.      clrf m
  1250.      clrf m10
  1251.     clrf count
  1252.  
  1253. Vavloh2d:                ; m is 2nd dec, use m10
  1254.        movf  count,w
  1255.        xorwf reslo,w
  1256.        btfsc STATUS,Z
  1257.        goto  Vavloend                
  1258.        incf  count,f
  1259.          incf  m10,f
  1260.        movlw 0xA        
  1261.        xorwf m10,w
  1262.        btfss STATUS,Z
  1263.        goto Vavloh2d
  1264.        clrf m10
  1265.        incf m,f
  1266.        goto Vavloh2d
  1267.  
  1268. Vavloend:
  1269.  
  1270.       clrf m100
  1271.       clrf m1000
  1272.       clrf count
  1273.  
  1274. Vavhih2d:
  1275.        movf  count,w
  1276.        xorwf reshi,w
  1277.        btfsc STATUS,Z
  1278.        goto  Vavhiend                
  1279.        incf  count,f
  1280.        incf  m100,f
  1281.        movlw 0xA        
  1282.        xorwf m100,w
  1283.        btfss STATUS,Z
  1284.        goto Vavhih2d
  1285.        clrf m100
  1286.        incf m1000,f
  1287.        goto Vavhih2d
  1288.  
  1289. Vavhiend:                 ; We have Vav as: INT m1000,m100 and FRAC  m10,m with Frac
  1290.        
  1291.        
  1292.  
  1293. Vavend:
  1294.          nop
  1295.          return
  1296.  
  1297.  
  1298. ;----------------------------------------------------------------------;
  1299. ;                    Display the Average velocity                               ;
  1300. ;----------------------------------------------------------------------;
  1301. Dispvav:
  1302.        
  1303.  movlw H'C0'       ;  position at beginning of second line
  1304.  call SendINS
  1305.  
  1306.  
  1307.  
  1308.  movf m1000, W     ;    x0 tens of km
  1309.  call SendASCII
  1310.  
  1311.  
  1312.  movf m100,W         ;   0x ones of km
  1313.  call SendASCII
  1314.  
  1315.  movlw "."                 ;  "." punto decimal  
  1316.  call SendCHAR
  1317.  
  1318.  movf m10,W             ;  "0.x0" decimal
  1319.  call SendASCII
  1320.  movf m, W              ;  "0.0x" decimal
  1321.  call SendASCII
  1322.              
  1323.  movlw "k"                   ;  k  
  1324.  call SendCHAR
  1325.  movlw "m"                 ;  m  
  1326.  call SendCHAR
  1327.  
  1328.  movlw "/"                   ;  /
  1329.  call SendCHAR
  1330.  
  1331.  movlw "h"                  ;  h
  1332.  call SendCHAR
  1333.  movlw "r"                   ;  r
  1334.  call SendCHAR
  1335.  
  1336.  movlw " "                   ;  " "
  1337.  call SendCHAR
  1338.  
  1339.  movlw "V"                ;  V
  1340.  call SendCHAR
  1341.  movlw "e"                  ;  e
  1342.  call SendCHAR
  1343.  
  1344.  movlw "l"                  ;  l
  1345.  call SendCHAR
  1346.  movlw "A"                 ;  A
  1347.  call SendCHAR
  1348.  
  1349.  
  1350.  movlw "v"                 ;  v
  1351.  call SendCHAR
  1352.  movlw "g"                 ;  g
  1353.  call SendCHAR
  1354.  movlw " "                   ;  " "
  1355.  call SendCHAR
  1356.  
  1357.  
  1358. Dispvavend:
  1359.                
  1360.   Return                    ; to change seconds for next second
  1361.      
  1362. ;--------------END OF AV SPEED-------------------
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.  
  1370.    
  1371.  
  1372.  
  1373. ; ---------------------------------------------------------------      
  1374. ;                   Instantaneous Speed  
  1375. ;-----------------------------------------------------------------      
  1376.  ;  Previous time values  are subtracted    the present
  1377.  ;  sec, TMR18, TMR0 values.
  1378.  ;  This time difference is the time between
  1379.  ; wheel pulses. This in turn for 26" wheel is a distance of 2.0747m
  1380. ; is covered in totms
  1381. ; ---------------------------------------------------------------      
  1382. ;                   Instantaneous Speed  
  1383. ;-----------------------------------------------------------------      
  1384. ; Note sec can only move between  0 and 9, 10 is a new 0
  1385. ; We start by reading sec, TMR18, TMR0 TO GET START TIME
  1386.  
  1387. Speed:
  1388.  
  1389.                        
  1390. Spdflg0:                  ; FIRST TIMEwith spdflg=0, second time with spdflg=1
  1391.                              ; First time captures timezero 0 in ms in totms
  1392.         clrw
  1393.         xorwf spdflg,w
  1394.         btfss STATUS ,Z
  1395.         goto Spdflg1    ; spdflg is not 0, this is the second time
  1396.      call Summs
  1397.      movf  mshi,w
  1398.      movwf totmshi  
  1399.      movf  mslo,w
  1400.      movwf totmslo
  1401.      incf spdflg,f  ; (spdflg = 1 for  SECOND TIME)
  1402.      return   ;jump back to main menu
  1403.      
  1404. Summs:   ; this routine is common to the first and second time
  1405.      movf sec,w     ; spdflg = 0
  1406.      movwf mbl      ; sec can only be in range 0 to 9
  1407.      clrf  mbh
  1408.       movlw 0x03                ; 1000 = 03E8
  1409.      movwf mah  
  1410.       movlw 0xE8                ; 1000 = 03E8
  1411.      movwf mal  
  1412.         call  Mult16x16 ;
  1413.      movf  mq2,w    ; hi byte
  1414.      movwf mshi
  1415.      movf  mq1,w    ; lo byte
  1416.      movwf mslo
  1417.      
  1418.         movf  TMR18,w
  1419.         movwf mal
  1420.         clrf  mah
  1421.      movlw D'56'
  1422.      movwf mbl
  1423.      clrf  mbh
  1424.         call  Mult16x16 ;  after themult we add
  1425.         movf  mshi,w
  1426.        movwf q1hi    
  1427.         movf  mslo,w
  1428.        movwf q1lo    
  1429.         movf  mq2,w
  1430.        movwf q2hi    
  1431.         movf  mq1,w
  1432.        movwf q2lo    
  1433.        call  Add
  1434.         movf  rhi,w
  1435.        movwf mshi
  1436.         movf  rlo,w
  1437.        movwf mslo   ; sum  (sec +TMR18)
  1438.                         ;TMR0 is a little more complex as we have to subtract39
  1439.                         ; before we can calculate ms in TMR0
  1440.        movf  TMR0,w
  1441.        movwf q1lo
  1442.        clrf  q1hi
  1443.        movlw  D'39'
  1444.        movwf q2lo
  1445.        clrf q2hi
  1446.        call Sub
  1447.        movf rlo, w
  1448.        movwf numlo
  1449.        clrf  numhi
  1450.        movlw 0x4
  1451.        movwf denlo
  1452.        clrf  denhi
  1453.         call  Div
  1454.  
  1455.         movf  mshi,w
  1456.        movwf q1hi    
  1457.         movf  mslo,w
  1458.        movwf q1lo    
  1459.         movf  reshi,w
  1460.        movwf q2hi    
  1461.         movf  reslo,w
  1462.        movwf q2lo    
  1463.        call  Add  
  1464.        movf  rhi,w
  1465.        movwf mshi
  1466.        movf  rlo,w
  1467.        movwf mslo ;   ( SEC +TMR18+ TMR0) in ms mshi/lo
  1468.  
  1469.        RETURN     ; Summs
  1470. Summsend:
  1471.  
  1472.  
  1473.  
  1474.  
  1475. Spdflg1: ; SECOND TIME is with spdflg =1
  1476.                          ; Second time captures timezero to  2nd Pulse
  1477.                     ; in ms, store  in totms2
  1478.                     ; for test we add 250ms to simulate time between
  1479.                     ; wheel pulses
  1480.                     ; 250ms delay
  1481.      ;movlw D'63'   ; DUMMY FOR TEST
  1482.      ;call nmsec     ; DUMMY FOR TEST            
  1483.  
  1484.         call Summs
  1485.  
  1486.      movf  mshi,w   ;
  1487.      movwf totms2hi ;  
  1488.      movf  mslo,w    ;  
  1489.      movwf totms2lo  ;
  1490.  
  1491.  
  1492. ; totms2 should be larger than totms,however if totms2 has just rolled,
  1493. ; then add 10000 to tot2
  1494.  
  1495. Testtot2:
  1496.       movf  totms2hi,w
  1497.       subwf totmshi,w
  1498.       btfss STATUS,C   ;compare for greater
  1499.       goto  Diffms     ;totms2 > totms  no add 10000 needed
  1500.       movlw 0xA        ;totms2 < totms, add 10000, hex 2710
  1501.          movlw 0x27
  1502.       movwf q1hi
  1503.          movlw 0x10
  1504.       movwf q1lo
  1505.       movf totms2hi,w
  1506.          movwf q2hi  
  1507.       movf totms2lo,w
  1508.          movwf q2lo
  1509.       call  Add     ; tot2 +10000
  1510.          movf  rhi,w
  1511.       movwf totms2hi
  1512.          movf  rlo,w
  1513.       movwf totms2lo  ; tot2 = tot2+10000
  1514.  
  1515.  
  1516.              
  1517. Diffms:
  1518.  
  1519.  
  1520.     ; sub  (tot2-tot1)for time between wheel pulses
  1521.  
  1522.         movf   totms2hi,w  ;
  1523.      movwf  q1hi  
  1524.         movf   totms2lo,w
  1525.      movwf  q1lo      
  1526.  
  1527.         movf   totmshi,w
  1528.      movwf  q2hi  
  1529.         movf   totmslo,w
  1530.      movwf  q2lo    
  1531.      call   Sub  ; result is  time diff, stored in rhi, rlo
  1532. tp2:
  1533.   ; we are almost ready to divide dist/time for speed
  1534.   ; complete equation is dist/time x3.6
  1535.   ; to avoid as far as possible fractions we multiply before divide
  1536.   ; but this time, better divide first.
  1537.  
  1538.   ; 2000            36        <--- this is more than 65536
  1539.   ; ----       x    --------
  1540.   ; denhi/lo         10    ( denhi/lo is sub result rhi/lo)
  1541.  
  1542.   ; so we can divide by 10 and x by 36 ( always,)
  1543.   ; so top  line is simply 7200.
  1544.   ; we finally have 7200/(denhi/lo) , SPEED IN HEX
  1545.  
  1546.  
  1547.      movf   rhi,w
  1548.         movwf  denhi
  1549.      movf   rlo,w
  1550.         movwf  denlo  ; denom is time in hex
  1551.      movlw  0x1C   ; 7200, hex 1C20
  1552.      movwf  numhi
  1553.      movlw  0x20   ; 7200, hex 1C20
  1554.      movwf  numlo
  1555.         call Div
  1556.                    ; the result , res, is  more than 1
  1557.                         ;and a remainder rmdr/den
  1558.                    ;we now have 6 free variables
  1559.                    ; mshi/lo  for INT hex speed lo is enough
  1560.                         ; totmshi/lo
  1561.                         ; totms2hi/lo    
  1562.                    ;we will reuse to convert  hex to decimal
  1563.  
  1564.         movf  reslo,w
  1565.      movwf mshi   ; INT part of hex speed ( hi, because FRAC will be in lo)
  1566.  
  1567.                    ;we will only use 1 decimal of
  1568.                         ;the hex speed remainder, so 1st  rmdrx10  
  1569.                    ;  so next calculation is
  1570.  
  1571.                           ; 10 x rmdrhi/lo
  1572.                    ; ---------------
  1573.                       ; denhi/lo
  1574.  
  1575.      movf rmdrhi,w
  1576.      movwf mah
  1577.      movf rmdrlo,w
  1578.      movwf mal
  1579.         clrf  mbh
  1580.         movlw 0x0A
  1581.         movwf mbl
  1582.      call  Mult16x16  ;( ten times top)  
  1583.      movf  mq2,w
  1584.      movwf numhi
  1585.      movf  mq1,w
  1586.      movwf numlo  ; the den is previously loaded so divide for
  1587.                   ; decimal part of speed ( still in hex)
  1588.         call  Div    ; we only use 1 decimal, so just use lo of Div result
  1589.      movf  reslo,w
  1590.      movwf mslo    ; FRAC  of speed in hex
  1591.                   ; now convert speed to decimal form
  1592.                   ; i.e. mshi, mslo --> 99.9 km/hr
  1593.  
  1594. Spdh2d:
  1595.  
  1596.         clrf m
  1597.         clrf m10
  1598.         clrf m100
  1599.         clrf m1000
  1600.         clrf count
  1601.  
  1602.  
  1603. Spdlo:
  1604.       movf  count,w
  1605.       xorwf mslo,w
  1606.       btfsc STATUS,Z
  1607.       goto  Spdhicnt                
  1608.       incf  count,f
  1609.          incf  m10,f
  1610.       movlw 0xA        
  1611.       xorwf m10,w
  1612.       btfss STATUS,Z
  1613.       goto Spdlo
  1614.       clrf m10
  1615.       incf m,f
  1616.       goto Spdlo
  1617.  
  1618. Spdhicnt:
  1619.         clrf m100    
  1620.         clrf m1000
  1621.         clrf count
  1622.  
  1623. Spdhi:
  1624.       movf  count,w
  1625.       xorwf mshi,w
  1626.       btfsc STATUS,Z
  1627.       goto  Spdhiend                
  1628.       incf  count,f
  1629.          incf  m100,f
  1630.       movlw 0xA        
  1631.       xorwf m100,w
  1632.       btfss STATUS,Z
  1633.       goto Spdhi
  1634.       clrf m100
  1635.       incf m1000,f
  1636.       goto Spdhi
  1637.  
  1638. Spdhiend:; We have filled m1000,m100 with INT and m10,m with Frac, of Vin.
  1639.         ; Note we only need m10 ( 1 decimal place)
  1640.      clrf spdflg ; reset to 0 for next pair of pulses
  1641.  
  1642.  
  1643.  
  1644.  
  1645.  
  1646.  
  1647.  
  1648.     ; incf spdflg,f  ; (spdflg = 1 for  SECOND TIME)
  1649.  
  1650.         return
  1651. ; ---------------------------------------------------------------**
  1652. ;                         End of Instantaneous Speed
  1653. ; ---------------------------------------------------------------**
  1654.  
  1655.  
  1656.  
  1657. Dispd:
  1658. ;----------------------------------------------------------------------;
  1659. ;                    Display the Instantaneous Speed (Speed)                               ;
  1660. ;----------------------------------------------------------------------;
  1661.        
  1662. movlw H'C0'       ;  position at beginning of second line
  1663. call SendINS
  1664.  
  1665.  
  1666.  
  1667. movf m1000, W     ;    x0 tens of km
  1668. call SendASCII
  1669.  
  1670.  
  1671. movf m100,W         ;   0x ones of km
  1672. call SendASCII
  1673.  
  1674. movlw "."         ;  "." punto decimal  
  1675. call SendCHAR
  1676.  
  1677. movf m10,W     ;  "0.x0" decimal
  1678. call SendASCII
  1679. movf m, W      ;  "0.0x" decimal
  1680. call SendASCII
  1681.            
  1682. movlw "k"         ;  k  
  1683. call SendCHAR
  1684. movlw "m"         ;  m  
  1685. call SendCHAR
  1686.  
  1687. movlw "/"         ;  /
  1688. call SendCHAR
  1689.  
  1690. movlw "h"         ;  h
  1691. call SendCHAR
  1692. movlw "r"         ;  r
  1693. call SendCHAR
  1694.  
  1695.  
  1696. movlw " "         ;  " "
  1697. call SendCHAR
  1698.  
  1699. movlw "S"         ;  S
  1700. call SendCHAR
  1701. movlw "p"         ;  p
  1702. call SendCHAR
  1703.  
  1704. movlw "e"         ;  e
  1705. call SendCHAR
  1706. movlw "e"         ;  e
  1707. call SendCHAR
  1708.  
  1709.  
  1710. movlw "d"         ;  d
  1711. call SendCHAR
  1712.  
  1713. Dispdend:
  1714.              
  1715.  Return    ; to change seconds for next second
  1716.      
  1717. ;--------------END OF Inst SPEED-------------------
  1718.  
  1719.     end
  1720. ;-----------------------------------------------------
  1721. ;             bike computer program end  ....enjoy
  1722. ;-----------------------------------------------------
  1723.  
  1724.  
  1725.  
  1726. ;                    WORK IN HAND
  1727.  
  1728. ; CLEAN UP  SPEED,  readout still a little jumpy,
  1729. ; can try integrating but need more space. Next version
  1730.  
  1731. ;           Coventions used in the program text.
  1732. ;Variables all small letters , exceptions, those defined
  1733. ; by microchip. e.g. STATUS
  1734. ;Labels: First letter always a Capital, exceptions imported
  1735. ; routines
  1736. ; Test points. These have  a comment DUMMY, the value of the code
  1737. ; has/had been changed for testing or simulating.  If YOU want
  1738. ;to polish  these points should be useful for value changes
  1739. ; example. In ISR the D'18' value to reach a sec is very slow.
  1740. ;Use for test , say 2, and you get going about 10 times  faster.
  1741. ;Also LCD INIT: can be bypassed to debug quicker
  1742.  
  1743.  
  1744. ;------------------------------------------------------------------------
  1745. ;                   End of the Simple Bike Computer
  1746. ;------------------------------------------------------------------------
A hozzászólás módosítva: Jan 31, 2013
(#) Hp41C válasza mhatalyak hozzászólására (») Jan 31, 2013 /
 
Szia!
Íme...

bike.zip
    
(#) mhatalyak válasza Hp41C hozzászólására (») Jan 31, 2013 /
 
Szia!
Nagyon szépen köszönöm! Szép napot!
Üdv!mhatalyak
A hozzászólás módosítva: Jan 31, 2013
(#) store92 hozzászólása Jan 31, 2013 /
 
Mplab-x ben, hol lehet beállítani, hogy debuggoláskor mutassa a program épp hol tart. Mert a régebbi verziókon mutatta ilyen zöld nyíllal, de ebben nem tudom, hogy kell. a régit meg nem tudom felrakni erre a gépre, mert nem megy valamiért.
(#) llaczo válasza Hp41C hozzászólására (») Jan 31, 2013 /
 
Köszönöm szépen az infót. ki fogom próbálni.
(#) n_yálastrubadúr hozzászólása Jan 31, 2013 /
 
Sziasztok!
Időközben meg lett a megoldás. De nem értem! A probléma az volt, hogy egy 8bites számot decimálássá alakított és ezt egy szegmenses kiejlzőn megjelenítettem multiplexálva. Basszus most ahogy írom leesett. 1-2-3 sorrendben kapcsolgattam a digitekhez a feteket és azok 0-ja a pic pwm-jéről ment. Ezért esett olykor úgy, hogy a pwm éppen 0 volt mikor a kijelző elvileg aktív.
Következő: »»   360 / 1222
Bejelentkezés

Belépés

Hirdetés
XDT.hu
Az oldalon sütiket használunk a helyes működéshez. Bővebb információt az adatvédelmi szabályzatban olvashatsz. Megértettem