12F629 LDR - Light Dependant Resistor


Closed Thread
Results 1 to 16 of 16

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    I had to really DIG to find this code. Here's the original firmware for the Micro-Bot with the old Intel 8749 controller. If this doesn't make you appreciate PBP - I just couldn't imagine what would..
    Code:
          ;                    " Micro-Bot "
           ; Intel 8749H Micro Program For Programmable Mobile Robot
    
                org     0           ; Start at 0.
                sel     rb0         ; Select register bank 0
                mov     r0,#18h     ; Set DIRECTION ram location pointer.
                mov     r1,#19h     ; Set TIME ram location pointer.
    
         begin: mov     a,#0ffh     ; Load clear display bits
                outl    bus,a       ; Clear Display.
                mov     a,#0f0h     ; Bits to Halt all motors ( CLR P1.0 )
                outl    p1,a        ; Halt Motors.
                clr     a           ; Clear Accumulator.
                in      a,p2        ; Get user keyPad input.
                cpl     a           ; Invert keypad entry 0 = 1.
                jb0     fwd         ; If Acc Bit 0 = 1 goto fwd
                jb1     rvs         ; If Acc Bit 1 = 1 goto rvs
                jb2     left        ; If Acc Bit 2 = 1 goto left
                jb3     right       ; If Acc Bit 3 = 1 goto right
                jb4     clear       ; If Acc Bit 4 = 1 goto clear / clear ram
                jb5     run         ; If Acc Bit 7 = 1 goto run / execute pgm
                jb6     time        ; If Acc Bit 6 = 1 goto time / set time
                jb7     pause       ; Pause / Stop routine.
                jmp     begin       ; Recycle until Keypress detected.
    
      clear:    mov     r0,#18h     ; TIME + DIRECTION Ram Clearing routine.
                mov     r3,#68h     ; 18H = Ram location #24d
                mov     a,#0        ; Zero's for ram locations.
    
       incrt:   mov     @r0,a       ;
                inc     r0          ;
                djnz    r3,incrt    ; Loop until all ram locations
                mov     r0,#18h     ; have been cleared, then goto begin.
                jmp     begin       ;
    
        fwd:    mov     @r0,#0f1h   ; Move to the address indicated in R0
                inc     r0          ; the output bits for FORWARD motion
                inc     r0          ; then increment R0 to next available
                mov     a,#1        ; direction ram location.
                outl    bus,a       ; Output a # 1 to display
    
        fwd1:   jt0     $           ; Loop here until the T0 input = 0
                clr     a           ; 0 indicates user pressed ENTER Key.
                jmp     begin       ; Goto routine BEGIN, wait for more input.
    
        rvs:    mov     @r0,#0f7h   ;
                inc     r0          ; Same as FWD routine for REVERSE direction.
                inc     r0          ;
                mov     a,#2        ; Load # 2 into ACC.
                outl    bus,a       ; Output # 2 to display.
    
        rvs1:   jt0     $           ; Stay here until user presses enter key.
                clr     a           ; Clear ACC.
                jmp     begin       ; Go wait for input.
    
        left:   mov     @r0,#0f5h   ; Left Direction.
                inc     r0          ; DITTO.
                inc     r0          ;
                mov     a,#3
                outl    bus,a
    
        left1:  jt0     $           ; DITTO.
                clr     a
                jmp     begin
    
        right:  mov     @r0,#0f3h   ;
                inc     r0          ; DITTO.
                inc     r0          ;
                mov     a,#4        ; Load # 4
                outl    bus,a       ; Display # 4
    
       right1:  jt0     $           ; DITTO.
                clr     a
                jmp     begin
    
       pause:   mov     @r0,#0f0h   ; Output bits to stop motors
                inc     r0
                inc     r0
                mov     a,#00       ; Show 0's on display for Pause indication.
                outl    bus,a
    
      pause1:   jt0     $           ; DITTO.
                clr     a           ;
                jmp     begin
    
        run:    mov     r0,#18h     ; Load DIRECTION Ram address.
                mov     r1,#19h     ; Load TIME Ram address.
    
        run1:   mov     a,@r0       ; Move DIRECTION bits to ACC.
                jz      begin       ; If ACC = 0 ( END RUN ) goto begin.
                outl    p1,a        ; Output DIRECTION bits to motors on P1.
                inc     r0          ; Increment DIRECTION ram address
                inc     r0          ; to next DIRECTION location.
                call    speed       ; Go get time to proceed in selected
                jmp     run1        ; direction, then return if finished.
    
        speed:  clr     a           ; Start here / Clear Acc.
                mov     a,@r1       ; Get selected TIME bits from ram.
                call    timer       ; Goto Routine for time delay.
                inc     r1          ; Increment too next TIME ram address.
                inc     r1          ;
                ret                 ; Return to calling routine.
    
        time:   inc     @r1         ; Make sure r1 isnt = 0 at first, and
                mov     a,@r1       ; then increment for next numbers.
                add     a,#display  ; Add Lookup table address to ACC.
                movp    a,@a        ; Move page to A addressed by A.
                outl    bus,a       ; Output the selected TIME to the display.
                call    delay       ; Delay between display digit updates.
                jz      reload      ; If A=0 goto subroutine Reload, else continue.
                jnt0    done        ; If enter key pressed goto done.
                jt0     time        ; If enter key not pressed recycle
                                    ; And keep updating the display.
       reload:  mov     @r1,#00H    ; Reload TIME ram address with 00's
                jmp     time        ; and start over from # 1.
    
        done:   inc     r1          ; If user pressed ENTER we come here
                inc     r1          ; increment to next TIME ram location
                jmp     begin       ; then go get more input.
    
        delay:  mov     r5,#2       ; Routine to establish about .5 seconds
                                    ; between display updates.
       delay1:  djnz    r5,delay2   ;
                ret                 ;
    
       delay2:  mov     r6,#0ffh    ;
    
       delay3:  mov     r7,#0ffh    ;
                djnz    r7,$        ;
                djnz    r6,delay3   ;
                jmp     delay1      ;
    
        timer:  mov     r7,#30      ; Timer routine for approx 1 second.
                mov     r6,#0ffh    ;
                dis     tcnti       ; Dissable Timer/Counter interupt.
                add     a,#1        ; Will cycle through until R5 = 0.
                mov     r5,a        ; Move user selected TIME data to R5.
    
        timer1: clr     a           ;
                mov     t,a         ; 3.57 Mhz crystal must be used
                strt    t           ; for this routine to be effective.
                djnz    r5,timer2   ; Decrement R5 then if not = 0 goto timer2.
                stop    tcnt        ; Stop timer/counter.
                ret                 ; Return to calling routine.
    
        timer2: jtf     timer3      ; Jump on timer overflow to timer3 routine.
    
        timer3: djnz    r6,timer2   ;
                jmp     timer4      ;
    
        timer4: mov     r6,#0ffh    ;
                djnz    r7,timer2   ; Loop until R7 = 0
                jmp     timer1      ;
    
       display: nop                 ; Define bytes for display.
                db      1           ; 1 To 60 Seconds.
                db      2           ;
                db      3           ;
                db      4           ;
                db      5           ;
                db      6           ;
                db      7           ;
                db      8           ;
                db      9           ;
                db      10h         ;
                db      11h         ;
                db      12h         ;
                db      13h         ;
                db      14h         ;
                db      15h         ;
                db      16h         ; At 60 seconds the display will reset
                db      17h         ; To 00 and start counting again from
                db      18h         ; 1.
                db      19h         ;
                db      20h         ; More time may be added to the Code,
                db      21h         ; by user if needed.
                db      22h         ;
                db      23h         ;
                db      24h         ;
                db      25h         ;
                db      26h         ;
                db      27h         ;
                db      28h         ;
                db      29h         ;
                db      30h         ;
                db      31h         ;
                db      32h         ;
                db      33h         ;
                db      34h         ;
                db      35h         ;
                db      36h         ;
                db      37h         ;
                db      38h         ;
                db      39h         ;
                db      40h         ;
                db      41h         ;
                db      42h         ;
                db      43h         ;
                db      44h         ;
                db      45h         ;
                db      46h         ;
                db      47h         ;
                db      48h         ;
                db      49h         ;
                db      50h         ;
                db      51h         ;
                db      52h         ;
                db      53h         ;
                db      54h         ;
                db      55h         ;
                db      56h         ;
                db      57h         ;
                db      58h         ;
                db      59h         ;
                db      60h         ; Output a number 60 to display
                db      0           ; If count over 60 seconds start over at 0.
     End                            ; That's All Folk's
    Yikes...;o)
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2


    Did you find this post helpful? Yes | No

    Default Wow

    @Bruce

    That sure is a lot of coding for the task described.
    And the display label sure is a lot too ! Quite a lot of repitition to get the display refreshed hey ?
    What kinf of display was it ?

    Kind regards

    Dennis

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    That sure is a lot of coding for the task described.
    And the display label sure is a lot too ! Quite a lot of repitition to get the display refreshed hey ?
    Yes. There's a big difference in doing everything in assembler VS using PBP.

    What kinf of display was it ?
    Just a plain old 2-digit 7-segment type.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. Stairwell light code from BS1 to PHP2.50a
    By vtt-info in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 21st December 2007, 17:32
  2. A/D on 16F767 for light tracking.
    By Ryan7777 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th November 2007, 05:56
  3. Reading a Light Dependent Resistor
    By kiwipiper in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 21st October 2007, 05:29
  4. Replies: 5
    Last Post: - 2nd March 2006, 09:21

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts