Overunity.com Archives is Temporarily on Read Mode Only!



Free Energy will change the World - Free Energy will stop Climate Change - Free Energy will give us hope
and we will not surrender until free energy will be enabled all over the world, to power planes, cars, ships and trains.
Free energy will help the poor to become independent of needing expensive fuels.
So all in all Free energy will bring far more peace to the world than any other invention has already brought to the world.
Those beautiful words were written by Stefan Hartmann/Owner/Admin at overunity.com
Unfortunately now, Stefan Hartmann is very ill and He needs our help
Stefan wanted that I have all these massive data to get it back online
even being as ill as Stefan is, he transferred all databases and folders
that without his help, this Forum Archives would have never been published here
so, please, as the Webmaster and Creator of these Archives, I am asking that you help him
by making a donation on the Paypal Button above.
You can visit us or register at my main site at:
Overunity Machines Forum



Control Circuit Design and Program

Started by Draco Rylos, June 06, 2009, 05:49:43 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Draco Rylos

I've been working on a program for a MCU (PIC16F628) using MPLAB IDE and Oshonsoft's PIC Simulator IDE, and have been successful at writing the program I'm attaching the schematics for the main circuit and its two sub-circuits, the source code of the program and hex file below. Tell me what you guys think of it and if you see any glaring mistakes I may have made.

Source Code

       list      p=16f628            ; list directive to define processor
       #include <p16f628.inc>        ; processor specific variable definitions
       errorlevel   -302             ;hide banking message
    ;*****   
     __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _LVP_OFF
    ;*****
    ;internal osc settings
    ;*****
    ; '__CONFIG' directive is used to embed configuration data within .asm file.
    ; The lables following the directive are located in the respective .inc file.
    ; See respective data sheet for additional information on configuration word.

    ;***** VARIABLE DEFINITIONS
w_temp        EQU     0x70          ; variable used for context saving
status_temp   EQU     0x71          ; variable used for context saving
Count1        EQU     0X20          ; First Counter for Delay
Count2        EQU     0X21          ; Second Counter for Delay
Count3        EQU     0X22          ; Third Counter for Delay

    ;**********************************************************************
          ORG     0x000             ; processor reset vector
          goto    Start             ; go to beginning of program
          ORG     0x004             ; interrupt vector location
          movwf   w_temp            ; save off current W register contents
          movf   STATUS,w           ; move status register into W register
          movwf   status_temp       ; save off contents of STATUS register
          movf    status_temp,w     ; retrieve copy of STATUS register
          movwf   STATUS            ; restore pre-isr STATUS register contents
          swapf   w_temp,f
          swapf   w_temp,w          ; restore pre-isr W register contents
          retfie                    ; return from interrupt
         
Start
          clrf     PORTA
          clrf     PORTB
          MOVLW    B'00000111'
          MOVWF    CMCON            ; Turn off comparator
          bsf      STATUS,RP0       ; bank one
          movlw    0xFF
          movwf    TRISA            ; porta all Input
          movlw    0x00
          movwf    TRISB            ; portb all Output
          bcf      STATUS,RP0       ; return to bank 0

          movlw   b'00000000'       ;See datasheet for prefered
          movwf   OPTION_REG        ;settings of OPTION_REG
         
          btfss   PORTA,0           ; Check if Upper Sensor = 1
          Call    Prestart          ; If not go to Prestart Subroutine
          Goto    Run               ; Then go to Operation Mode

Prestart
          movlw b'10111000'         ; Set Refill Mode
          btfsc PORTA,0             ; Check If Upper Sensor = 1
          movlw b'11000000'         ; Then Set Operation Mode
          movwf PORTB               ; Move to PORTB
          btfss PORTA,0             ; Check If Upper Sensor = 1
          goto Prestart             ; If Not Return to Top of subroutine
          Return                    ; Return to Start

Run
          movlw b'11000000'         ; Set Operation Mode
          btfss PORTA,0             ; Check if Upper Sensor = 1
          movlw b'11100000'         ; Set Warning Mode
          movwf PORTB               ; Move to PortB
          btfss PORTA,1             ; Check If Lower Sensor = 1
          Call Refill               ; Go to Refill Subroutine
          Goto Run                  ; Return to Top
         
         
Refill
          movlw b'10111000'         ; Set Refill Mode
          btfsc PORTA,0             ; Check If Upper Sensor = 1
          movlw b'11000000'         ; Then Set Operation Mode
          movwf PORTB               ; Move to PORTB
          btfss PORTA,0             ; Check If Upper Sensor = 1
          goto Refill               ; If Not Return to Top of subroutine
          Return                    ; Return to Start
         
          END

Hex Code

:020000040000FA
:020000000C28CA
:08000800F0000308F10071088B
:100010008300F00E700E09008501860107309F00F5
:100020008316FF3085000030860083120030810087
:10003000051C1B202228B8300518C0308600051C7E
:100040001B280800C030051CE0308600851C2920D4
:100050002228B8300518C0308600051C2928080061
:02400E00503F21
:00000001FF
We are the BORG..... We will add your biological and technological distinctiveness to our own. Your culture will adapt to service US. RESISTANCE IS FUTILE

dankie

Nice work Draco

Pmed you ;)

I am impressed

Draco Rylos

Thanks for your support. :D I've changed my code some and added a prestart indicator test and took out a section only used once and just pointed the program to my primary refill subroutine.

Here's my new code

       list      p=16f628            ; list directive to define processor
       #include <p16f628.inc>        ; processor specific variable definitions
       errorlevel   -302             ;hide banking message
    ;*****   
     __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF & _LVP_OFF
    ;*****
    ;internal osc settings
    ;*****
    ; '__CONFIG' directive is used to embed configuration data within .asm file.
    ; The lables following the directive are located in the respective .inc file.
    ; See respective data sheet for additional information on configuration word.

    ;***** VARIABLE DEFINITIONS
w_temp        EQU     0x70          ; variable used for context saving
status_temp   EQU     0x71          ; variable used for context saving
Count1        EQU     0X20          ; First Counter for Delay
    ;**********************************************************************
          ORG     0x000             ; processor reset vector
          goto    Start             ; go to beginning of program
          ORG     0x004             ; interrupt vector location
          movwf   w_temp            ; save off current W register contents
          movf   STATUS,w           ; move status register into W register
          movwf   status_temp       ; save off contents of STATUS register
          movf    status_temp,w     ; retrieve copy of STATUS register
          movwf   STATUS            ; restore pre-isr STATUS register contents
          swapf   w_temp,f
          swapf   w_temp,w          ; restore pre-isr W register contents
          retfie                    ; return from interrupt         
Start
          clrf     PORTA
          clrf     PORTB
          MOVLW    B'00000111'
          MOVWF    CMCON            ; Turn off comparator
          bsf      STATUS,RP0       ; bank one
          movlw    0xFF
          movwf    TRISA            ; porta all Input
          movlw    0x00
          movwf    TRISB            ; portb all Output
          movlw   b'00000000'       ;See datasheet for prefered
          movwf   OPTION_REG        ;settings of OPTION_REG
          bcf      STATUS,RP0       ; return to bank 0
          call    Systest
          btfss   PORTA,0           ; Check if Upper Sensor = 1
          Call    Refill            ; If not go to Refill Subroutine
          Goto    Run               ; Then go to Operation Mode
Systest
          movlw b'10000000'         ; Set PortB,7 High the others Low
          movwf PORTB               
          movlw 0x05                ; Set Count1 to 05H
          movwf Count1             
          call Delay                ; Call Delay Subroutine
          movlw b'01000000'         ; Set PortB,6 High the others Low
          movwf PORTB
          movlw 0x05                ;Reset Counter1 to 05H
          movwf Count1
          call Delay                ;Call Delay Subroutine
          movlw b'00100000'         ; Set PortB,5 High the others Low
          movwf PORTB
          movlw 0x05                ;Reset Counter1 to 05H
          movwf Count1
          call Delay                ; Call Delay Subroutine
          movlw b'00010000'         ; Set PortB,4 High the others Low
          movwf PORTB
          movlw 0x05                ; Reset Counter to 05H
          movwf Count1               
          Call Delay                ; Call Delay Subroutine
          movlw b'11110000'         ; Set All Indicators High
          movwf PORTB
          movlw 0x05                ; Last Counter Reset to 05H
          movwf Count1
          call Delay                ; Call Delay Subroutine
          movlw b'10000000'         ; Turn on Power LED
          movwf PORTB
          RETURN                    ;Return to main program
Run
          movlw b'11000000'         ; Set Operation Mode
          btfss PORTA,0             ; Check if Upper Sensor = 1
          movlw b'11100000'         ; Set Warning Mode
          movwf PORTB               ; Move to PortB
          btfss PORTA,1             ; Check If Lower Sensor = 1
          Call Refill               ; Go to Refill Subroutine
          Goto Run                  ; Return to Top
Refill
          movlw b'10111000'         ; Set Refill Mode
          btfsc PORTA,0             ; Check If Upper Sensor = 1
          movlw b'11000000'         ; Then Set Operation Mode
          movwf PORTB               ; Move to PORTB
          btfss PORTA,0             ; Check If Upper Sensor = 1
          goto Refill               ; If Not Return to Top of subroutine
          Return                    ; Return to Start
Delay
          decfsz Count1,1           ;Decrement Count1 1
          goto Delay                ;If Count1 > 0 Return to top
          Return                    ;Return to Previous place

          END
We are the BORG..... We will add your biological and technological distinctiveness to our own. Your culture will adapt to service US. RESISTANCE IS FUTILE