A Microcontroller Discussion Board
September 07, 2010, 03:28:14 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: If this is your first visit, be sure to check out the Help by clicking the link below.
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Polling Inputs  (Read 325 times)
0 Members and 1 Guest are viewing this topic.
SkeeterB
Newbie
*
Posts: 1



View Profile
« on: June 04, 2009, 11:08:14 AM »

I need help setting up my program to poll the inputs and give the proper output according to the logic diagram below. I've already established the initialization vectors and the first part of it. Here's the code I have so far.

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_ON & _LVP_OFF
    ;*****
    ;;   __CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _INTRC_OSC_CLKOUT & _MCLRE_ON & _LVP_OFF
    ;*****
    ;internal osc settings - choice of two
    ;*****
    ; '__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
    ;*****
    ;**********************************************************************
          ORG     0x000             ; processor reset vector
          goto    main              ; 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
    ; isr code can go here or be located as a call subroutine elsewhere
          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
    ;*****
main
    ; remaining code goes here
          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
    ;*****
            bsf    PORTB,7     ; Turn on Power LED
         
    ;*****
   
    ; here is where my polling is gonna go for system operations.       
           
           goto main

   ;*****
          END

Here is the logic diagram of my circuit

(Operation)
Upper (RA0) + Lower Sensor (RA1) = 1 Then Operation (RB6) = 1; Warn (RB5) = 0; Refill (RB3, RB4) = 0
Upper Sensor = 0 + Lower Sensor = 1 Then Operation = 1; Warn = 1; Refill = 0

(Refilling)
Upper + Lower Sensor = 0 Then Operation = 0; Warn = Flashing; Refill = 1
If Upper Sensor = 0 Then Operation = 0, Warn = Flashing, Refill = 1
If Upper Sensor = 1 Then Operation = 1; Warn = 0; Refill = 0
(End Refilling)
« Last Edit: June 04, 2009, 11:28:21 AM by SkeeterB » Logged
A Microcontroller Discussion Board
« on: June 04, 2009, 11:08:14 AM »

 Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC | Sitemap Valid XHTML 1.0! Valid CSS!