Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Getting message to call using a debouncing circuit

Status
Not open for further replies.

Daniel Payne

New Member
Need helping implementing interrupt to call message by spdt switch .
Use portb or use porta ?

Code:
#include <GENERAL.h>    ;This is the header file you created for this lab#1
     
;;; Blinking Module Variables and Constants
;#include "p16f84a.inc"
;__CONFIG _FOSC_HS & _WDTE_OFF & _PWRTE_OFF & _CP_OFF
ms     set        0x0C 
delay_outer set  0x0D
delay_inner set  0x0E

constant LCD_ARRAY_START = 0x0F
constant LCD_ARRAY_END    = 0x37
constant LCD_ROW_LENGTH    = 0x10
constant LCD_CMD_DELAY    = 0x02
constant LCD_BLINK_DELAY = 0xF0
line_ctr    EQU 0x38
DRAM_ADDRESS EQU 0x39
blink_ctr    EQU 0x3A
   
   
RS            EQU        0x0
EN            EQU        0x1
LCD_DATA    EQU        0x06
   
; Blinking Module Variables End
TEMP    EQU        0X0E
TEMP1    EQU        0X0F
TEMP2    EQU        0X10
OFFSET    EQU        0X21
MS_SW    EQU        0X22        ; Acts as a sofware flag.
;CHOICE        EQU        0X17        ; THIS IS REVSERVED FOR CHOOSING A PATTERN
;FINAL        EQU        0X18
STATUS_TEMP    EQU        0X14        ; THIS IS LOCATION OF STATUS TEMP
W_TEMP        EQU        0X15
;================================================================================
;================ Setup =========================================================
;================================================================================

    ; Set CONFIG word and Interrupt

        __CONFIG    0X3FF6
- is the control bits for CONFIG register

        ORG        0X0000        ;RESET or WDT reset vector
        GOTO    START
     
        ORG        0X0004        ;Regular INT vector

;=====================================================================================
;THIS IS MY INTERRUPT PATTERN
;PUSH

ISR
 
        MOVWF    W_TEMP            ; SAVING THE W
        SWAPF    STATUS,W        ; MOVING THE STATUS FOR PUSH
        MOVWF    STATUS_TEMP        ; SAVING THE STATUS FLAGS
                                         
        INCF    OFFSET,F         ; THIS IS MY VARAIBLE FOR DECIDING ON PATTERNS
 
        SWAPF    STATUS_TEMP,W    ;RESTORING THE STATUS
        MOVWF    STATUS            ;
        SWAPF    W_TEMP,F        ;RESTORING THE W
        SWAPF    W_TEMP,W        ;
        MOVF    PORTA,F            ; DUMMY
        BCF        INTCON,GIE        ; CLEAR FLAG
                 

        RETFIE            ; Return From Interrupt 
;--------------------------TIME DELAY ROUTINE-------------------------------------------
DELAY 
    NOP                    ;1 cycle
    NOP                    ;1 cycle
    NOP                   
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP
    NOP                 ;1 cycle
    MOVLW    0x45        ;1 cycle
    MOVWF    0x41        ;1 cycle
    MOVLW    0xFF        ;1 cycle
    MOVWF    0x42        ;1 cycle
LOOP1
    MOVLW    0x20        ;1
    MOVWF    0x43        ;1
LOOP2
    MOVLW    0x10        ;1
    MOVWF    0x44        ;1
LOOP3
    DECFSZ    0x44,F        ;1(2)
    GOTO    LOOP3        ;2
    DECFSZ    0x43,F        ;1(2)
    GOTO    LOOP2        ;2
    DECFSZ    0x42,F        ;1(2)
    GOTO    LOOP1        ;2
    RETURN
;--------------------------ON CALL TOGGLE E-------------------------------------------
; This subroutine causes E to pulse hi to low
; PORTA RA0 is the E bit
;-------------------------------------------------------------------------------------
TOGGLE_E                ;Toggle Function
    BCF        PORTA,0        ;Clear PORTA
    nop
    nop
    nop
    BSF        PORTA,0        ;Set PORTA as outputs
    NOP
    NOP
    NOP
    RETURN

;---------------------------Clear the LCD screen--------------------------------------
LCDCLR
    CALL    DELAY        ;Delay routines is called in order to display the message longer
    CALL    DELAY        ;     before it clears
    CALL    DELAY
    CALL    DELAY

    CALL    DELAY
    CALL    DELAY
    CALL    DELAY
    CALL    DELAY

    CALL    DELAY
    CALL    DELAY
    CALL    DELAY
    CALL    DELAY

    BCF        PORTA,1        ;Writes instruction to LCD to clear everytime a new message pops up
    MOVLW    0X01        ;This command clears the LCD 
    MOVWF    PORTB        ;Command is sent to PORTB in order to Clear the sceen
    ;MOVWF   PORTA
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;calls delay
     

    BSF        PORTA,1        ;Reads instruction to LCD to clear everytime a new message pops up
 
    CLRW                ;Clears W register
    MOVWF    OFFSET        ;Moves W to offset register
    GOTO    BOSS        ;Go to BOSS to check the switches

;-------------------------INITIATE LCD--------------------------------------------
; Turns on the LCD screen
; PORTA RA0 is the RS bit
LCD1
    BCF        PORTA,1        ;Write to instruction regiser

    MOVLW    0X30        ;sends messages to LCD
    MOVWF    PORTB        ;sets PORTB to outputs
    ;MOVWF   PORTA
    CALL    TOGGLE_E    ;Call TOGGLE_E
    CALL    DELAY        ;Call DELAY

    MOVLW    0X30        ;sends messages to LCD
    MOVWF    PORTB        ;sets PORTB to outputs
    ;MOVWF   PORTA
    CALL    TOGGLE_E    ;Call TOGGLE_E
    CALL    DELAY        ;Call DELAY

    MOVLW    0X30        ;sends messages to LCD
    MOVWF    PORTB        ;sets PORTB to outputs
    ;MOVWF   PORTA
    CALL    TOGGLE_E    ;Call TOGGLE_E
    CALL    DELAY        ;Call DELAY

    MOVLW    0X38        ;Enables 8 bit data transfer and dual line display on PORTB
    MOVWF    PORTB
    ;MOVWF   PORTA
    CALL    TOGGLE_E    ;CALL TOGGLE_E
    CALL    DELAY        ;activate delay routine

    MOVLW    0X0C        ;Turns the LCD screen on
    MOVWF    PORTB
    ;MOVWF   PORTA
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;activate Delay routine

    MOVLW    0X01        ;Puts display in the upper left position
    MOVWF    PORTB
    ;MOVWF   PORTA
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;activate delay routine

    MOVLW    0X06        ;Address counter incremented after each display
    MOVWF    PORTB
    ;MOVWF   PORTA
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;activate delay routine

    MOVLW    0X02        ;Sets address counter to zero, puts display into home position
    MOVWF    PORTB
    ;MOVWF   PORTA
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;activate delay routine

    BSF        PORTA,1        ;Write to data register
    RETURN
;-------------------------------------------------------------------------------------
;Seciton of Program:Long Table with messages-
;Function: Writes the messages onto the LCD.
;           (Allows access to table content)
;-------------------------------------------------------------------------------------
LONGSUB

    MOVWF    TEMP1            ;Save table offset to a temp place
    MOVLW    HIGH MSG        ;Retrieves high byte
    MOVWF    PCLATH            ;Updates PCH register
    MOVF    TEMP1,W            ;Moves offset to W register
    ADDLW    LOW MSG            ;Retrieves low byte
    BTFSC    STATUS,C        ;Check overflow from PCL to PCH
    INCF    PCLATH,F        ;Update the overflow on PCH
    MOVWF    PCL

;    ORG     0x01F0            ;Register that was required to use on the lab
MSG                         ;Message1
    DT        "I'm feel like im gonna fail this class " 
    DT        0X00
    RETURN
 
LONGSUB2

    MOVWF    TEMP1            ;Save table offset to a temp place
    MOVLW    HIGH MSG2        ;Retrieves high byte
    MOVWF    PCLATH            ;Updates PCH register
    MOVF    TEMP1,W            ;Moves offset to W register
    ADDLW    LOW MSG2        ;Retrieves low byte
    BTFSC    STATUS,C        ;Check overflow from PCL to PCH
    INCF    PCLATH,F        ;Update the overflow on PCH
    MOVWF    PCL

MSG2                        ;Message2
    DT        "Expected December 2018 graduation "
    DT        0x00
    RETURN

LONGSUB3

    MOVWF    TEMP2            ;Save table offset to a temp place
    MOVLW    HIGH MSG3        ;Retrieves high byte
    MOVWF    PCLATH            ;Updates PCH register
    MOVF    TEMP2,W            ;Moves offset to W register
    ADDLW    LOW MSG3        ;Retrieves low byte
    BTFSC    STATUS,C        ;Check overflow from PCL to PCH
    INCF    PCLATH,F        ;Update the overflow on PCH
    MOVWF    PCL

                     
MSG3                         ;Message3
    DT        "I AM EET Major " 
    DT        0X00
 
    RETURN


LONGSUB4
    MOVWF    TEMP2            ;Save table offset to a temp place
    MOVLW    HIGH MSG4        ;Retrieves high byte
    MOVWF    PCLATH            ;Updates PCH register
    MOVF    TEMP2,W            ;Moves offset to W register
    ADDLW    LOW MSG4        ;Retrieves low byte
    BTFSC    STATUS,C        ;Check overflow from PCL to PCH
    INCF    PCLATH,F        ;Update the overflow on PCH
    MOVWF    PCL

MSG4                        ;Message4
    DT        "I HOPE HSIUNG PASSES ME ."
    DT        0x00

    RETURN
;------------------------------------------------------------------------------------
;Section: Start fo the program
;Funtion: THE starrting place of the user codes, sets the inputs and outputs.
;            PortB is all outputs while PortA is made up of both inpusts and outputs.
;Hardware: RA2-RA4 are inputs and RA0-RA1 are outputs
;------------------------------------------------------------------------------------

START
    MOVLW    0X00            ;starts off with all 0's on porta
    MOVWF    PORTA            ;move it to port a AND B
    MOVWF    PORTB            ;ZEROS OUTS THE PORTS
 
    BSF        STATUS,RP0    ;changes to bank 1
    MOVLW    0X1C        ;
    MOVWF    TRISA        ;sets I/O through TRISA
    MOVLW    0X00
    MOVWF    TRISB        ;sets I/O through TRISB
    BCF        STATUS,RP0    ;changes to bank 0


    MOVLW     0X88
    MOVWF    INTCON 
 
    CALL    LCD1        ;Runs LCD display
    MOVLW    0XFF        ;Moves 0xFF to OFFSET
    MOVWF    OFFSET 
    BSF        PORTA,3     
 
    CLRW                ;Clears W register
    MOVWF    OFFSET        ;Moves to OFFSET
;-------------------------------------------------------------------------------------
;Section: Switch Checker
;Function: Checks the switches for highs or lows in order to determine which LCD
;            message will display.
;Hardware: RA2 is switch 1
;          RA3 is switch 2
;          RA4 is switch 3
;-------------------------------------------------------------------------------------
;BOSS
    ;BTFSC    PORTA,RA2    ;Check if switch 1 is high, Skip if low
    ;GOTO    DISPLAY        ;If high run display
    ;BTFSC    PORTA,RA3    ;Check if switch 2 is high, Skip if low
;    GOTO    DISPLAY2    ;If high run display 2
;    BTFSC    PORTA,RA4    ;Check if switch 3 is high, Skip if low
;    GOTO    DISPLAY3    ;If high run display 3
;    BTFSS    PORTA,RA2    ;Check if switch 1 is low, Skip if high
;    BTFSS    PORTA,RA3    ;Check if switch 2 is low, Skip if high
;    BTFSS    PORTA,RA3    ;Check if switch 3 is low, Skip if high
;    GOTO    DISPLAY4    ;If low run Display 4
;    GOTO    BOSS        ;Check switches again
;    GOTO    $            ;Goes to stop
 
;=====================================================================================
;THIS IS THE BEGINNING OF THE PROGRAM THAT CONTROLS THE PATTERN
BOSS 

        MOVF    OFFSET,W        ; THIS VARIABLE RESERVED
        MOVWF    FINAL

        XORLW    0X02            ; DECIDE TO PICK PAT1
        BTFSC     STATUS,Z        ;
        CALL    DISPLAY             ;
     
        XORLW    0X04            ; DEICDE TO PICK PAT2
        BTFSC     STATUS,Z        ;
        CALL    DISPLAY2        ;

        XORLW    0X06            ; DEICDE TO PICK PAT3
        BTFSC     STATUS,Z        ;
        CALL    DISPLAY3            ;

        XORLW    0X08            ; RESET THE PATTERNS
        BTFSC    STATUS,Z
        CALL    DISPLAY4
     
        XORLW    0X10           ;
        BTFSC    STATUS,Z       '
        CLRF     OFFSET
   
        SUBLW    0X10            ; SAFETY MEASURE TO STOP COUNTS GREATER THAN 8
        BTFSC    STATUS,C
        CLRF    OFFSET
     

        GOTO    BOSS            ; GO BACK TO LOOKING

;--------------------------------------------------------------------------------------
;Section of program: First Display
;Function: Writes the first message to the LCD screen
;           First message is "I'm feel like im gonna fail this class "
;--------------------------------------------------------------------------------------

DISPLAY
    CLRWDT
    MOVF    OFFSET,W    ;Moves offset to W register
    INCF    OFFSET,F    ;Increment OFFSET by 1
    CALL    LONGSUB        ;Runs LONGSUB routine
    MOVWF    PORTB        ;changes PORTB as output
    IORLW    0X00        ;0x00 to W_REG
    BTFSC    STATUS,Z    ;Test bit status for zero, skip if zero
    GOTO    LCDCLR        ;Clears LCD
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    GOTO    DISPLAY        ;repeats DISPLAY loop
    ;GOTO    SHIFT4
STOP
    GOTO     $            ;Stops the program

;---------------------------------------------------------------------------------------
;Section of Program: Second Display routine
;Function: Writes the Second message to the LCD screen
;            Second message is "Expected December 2018 graduation"
;---------------------------------------------------------------------------------------

DISPLAY2
    CLRWDT
    MOVF    OFFSET,W    ;Moves offset to W register
    INCF    OFFSET,F    ;Increment OFFSET by 1
    CALL    LONGSUB2    ;Runs LONGSUB2 routine
    MOVWF    PORTB        ;changes PORTB as output
    IORLW    0X00        ;0x00 to W_REG
    BTFSC    STATUS,Z    ;Test bit status for zero, skip if zero
    GOTO    SHIFT2        ;Shifts entire display to the left SHIFT2
    ;GOTO    SHIFT4
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    GOTO    DISPLAY2    ;repeats DISPLAY2 loop
   ; STOP
    ;GOTO   $
;---------------------------------------------------------------------------------------
;Section of Program: Third Display routine
;Function: Writes the third message to the LCD screen
;            THIRD message is "I AM EET Major "
;---------------------------------------------------------------------------------------
DISPLAY3
    CLRWDT
    MOVF    OFFSET,W    ;Moves offset to W register
    INCF    OFFSET,F    ;Increment OFFSET by 1
    CALL    LONGSUB3    ;Runs LONGSUB3 routine
    MOVWF    PORTB        ;changes PORTB as output
    IORLW    0X00        ;0x00 to W_REG
    BTFSC    STATUS,Z    ;Test bit status for zero, skip if zero
    GOTO    SHIFT3        ;Shifts entire display to the right
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    GOTO    DISPLAY3    ;repeats DISPLAY loop
;    STOP
 ;   GOTO    $
;---------------------------------------------------------------------------------------
;Section of Program: Fourth Display routine
;Function: Writes the fourth message to the LCD screen
;            Second message is "I HOPE HSIUNG PASSES ME ."
;---------------------------------------------------------------------------------------
DISPLAY4
    CLRWDT
    MOVF    OFFSET,W    ;Moves offset to W register
    INCF    OFFSET,F    ;Increment OFFSET by 1
    CALL    LONGSUB4    ;Runs LONGSUB4 routine
    MOVWF    PORTB        ;changes PORTB as output
    IORLW    0X00        ;0x00 to W_REG
    BTFSC    STATUS,Z    ;Test bit status for zero, skip if zero
    GOTO    $         
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    GOTO    DISPLAY4    ;repeats DISPLAY loop
;--------------------------------------------------------------------------------------
;Section of Program: Display shift for second message
;Function: Shifts entire display to the left,Display will flash on/off twice
;--------------------------------------------------------------------------------------
SHIFT2
    BCF        PORTA,1        ;Writes to instruction register

    MOVLW    0X18        ;Shifts entire display to left
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
 
    MOVLW    0X18        ;Shifts entire display to left
    MOVWF    PORTB
    CALL    TOGGLE_E     
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine

    MOVLW    0X18        ;Shifts entire display to left
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine

    MOVLW    0X18        ;Shifts entire display to left
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine

    MOVLW    0X18        ;Shifts entire display to left
    MOVWF    PORTB
    CALL    TOGGLE_E     
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine

    MOVLW    0X18        ;Shifts entire display to left
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine

    MOVLW    0X18        ;Shifts entire display to left
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
 
    MOVLW    0X18        ;Shifts entire display to left
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine

    MOVLW    0X18        ;Shifts entire display to left
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
 
    MOVLW    0X08        ;OFF display
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine

    MOVLW    0X0C        ;ON display
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine 
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine

    MOVLW    0X08        ;OFF display
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
 
    MOVLW    0X0C        ;ON display
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine 
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine 
    BSF        PORTA,1        ;Reads to the instruction register
    CLRW                ;Clears W
 
    MOVWF    OFFSET        ;Moves W to offset
    GOTO    LCDCLR        ;Clears LCD screen

;--------------------------------------------------------------------------------------
;Section of Program: Display shift for Third message
;Function: Shifts entire display to the right
;--------------------------------------------------------------------------------------
SHIFT3
    BCF        PORTA,1        ;Write to instruction register

    MOVLW    0X1C        ;Shifts display to the right
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine 
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine

    MOVLW    0X1C        ;Shifts display to the right
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
 

    MOVLW    0X1C        ;Shifts display to the right
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine

    MOVLW    0X1C        ;Shifts display to the right
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine 
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine

    MOVLW    0X1C        ;Shifts display to the right
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
 
    MOVLW    0X1C        ;Shifts display to the right
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine

    MOVLW    0X1C        ;Shifts display to the right
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine 
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine

    MOVLW    0X1C        ;Shifts display to the right
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
 
    MOVLW    0X1C        ;Shifts display to the right
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
 
    MOVLW    0X1C        ;Shifts display to the right
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
 
    MOVLW    0X1C        ;Shifts display to the right
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine

    MOVLW    0X1C        ;Shifts display to the right
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine 
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine

    MOVLW    0X1C        ;Shifts display to the right
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
 
    MOVLW    0X1C        ;Shifts display to the right
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine

    MOVLW    0X1C        ;Shifts display to the right
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine 
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine

    MOVLW    0X1C        ;Shifts display to the right
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
 
 
    BSF        PORTA,1        ;Reads to instruction register
    CLRW                ;Clear W register
    MOVWF    OFFSET        ;Moves W to offset
    GOTO    LCDCLR        ;Clears the LCD



;********************************************************


SHIFT4
    BCF        PORTA,1        ;Write to instruction register
   

    MOVLW    0X08        ;Shifts display to the right
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine

    MOVLW    0X0C        ;Shifts display to the right
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine 
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine

    MOVLW    0X08        ;Shifts display to the right
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
 
    MOVLW    0X0C        ;Shifts display to the right
    MOVWF    PORTB
    CALL    TOGGLE_E    ;Toggles E
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine 
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine
    CALL    DELAY        ;Runs delay routine 
 
    BSF        PORTA,1        ;Reads to instruction register
    CLRW                ;Clear W register
    MOVWF    OFFSET        ;Moves W to offset
    GOTO    LCDCLR        ;Clears the LCD



;**************************************************************************



;**********************************************************
;;;; BLINKING Module functions
;; Delay Function
;**********************************************************
Delay_ms  ; argument is passed through the ms variable
 
    movlw 0x19
Delay_1ms
    movwf delay_outer
    decfsz ms , 1
    goto Delay_L1
    goto Delay_end
   
Delay_L1
        movwf delay_inner
        decfsz delay_outer , 1
        goto Delay_L2
        goto Delay_1ms
Delay_L2
       decfsz delay_inner , 1
       goto Delay_L3
       goto Delay_L1
 
Delay_L3
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
        NOP
     
        goto Delay_L2
Delay_end
        return
        ;
        ;
        ;
        ;
        ;
     
LCD_INIT    ; RS ---> RA0
        ; EN ---> RA1
        ; DATA ---> PORTB
        BSF   STATUS , RP0
        MOVLW  0x00
        MOVWF  TRISB
        BCF       TRISA , RS
        BCF       TRISA , EN
        BCF   STATUS , RP0

        BCF PORTA , RS ; RS_LOW
        MOVLW 0x00
        MOVWF LCD_DATA ; Data = 0
        BSF PORTA , EN ; En = 1
        ; ; Delay
        MOVLW   LCD_CMD_DELAY
        MOVWF   ms
        call Delay_ms
        ;
        BCF PORTA , EN ; En = 0
        ; ; Delay
        MOVLW   LCD_CMD_DELAY
        MOVWF   ms
        call Delay_ms
        ;
        MOVLW 0x3B ;
        MOVWF LCD_DATA ; Data = 0x3B
        BSF PORTA , EN ; En = 1
        ; ; Delay
        MOVLW   LCD_CMD_DELAY
        MOVWF   ms
        call Delay_ms
        ;
        BCF PORTA , EN ; En = 0
        ; ; Delay
        MOVLW   LCD_CMD_DELAY
        MOVWF   ms
        call Delay_ms
        ;
        MOVLW 0x0F ;
        MOVWF LCD_DATA ; Data = 0x0F
        BSF PORTA , EN ; En = 1
        ; ; Delay
        MOVLW   LCD_CMD_DELAY
        MOVWF   ms
        call Delay_ms
        ;
        BCF PORTA , EN ; En = 0
        ; ; Delay
        MOVLW   LCD_CMD_DELAY
        MOVWF   ms
        call Delay_ms
        ;
        MOVLW 0x80 ;
        MOVWF LCD_DATA ; Data = 0x80
        BSF PORTA , EN ; En = 1
        ; ; Delay
        MOVLW   LCD_CMD_DELAY
        MOVWF   ms
        call Delay_ms
        ;
         BCF PORTA , EN ; En = 0
        ; ; Delay
        MOVLW   LCD_CMD_DELAY
        MOVWF   ms
        call Delay_ms
        ;
        ; LCD CLEAR DISPLAY
        BCF PORTA , RS ; RS = 0
        MOVLW 0x01 ;
        MOVWF LCD_DATA ; Data = 0x01
        ; ; Delay
        MOVLW   LCD_CMD_DELAY
        MOVWF   ms
        call Delay_ms
        ;
        BSF PORTA , EN ; En = 1
        ; ; Delay
        MOVLW   LCD_CMD_DELAY
        MOVWF   ms
        call Delay_ms
        ;
        BCF PORTA , EN ; En = 0
        ; ; Delay
        MOVLW   LCD_CMD_DELAY
        MOVWF   ms
        call Delay_ms
        ;
        ;;
        ;; Cursor OFF
        MOVLW 0x0C ;
        MOVWF LCD_DATA ; Data = 0x0C
        BCF PORTA , RS ; RS = 0
        BSF PORTA , EN ; En = 1
        ; ; Delay
        MOVLW   LCD_CMD_DELAY
        MOVWF   ms
        call Delay_ms
        ;
        BCF PORTA , EN ; En = 0
        ; ; Delay
        MOVLW   LCD_CMD_DELAY
        MOVWF   ms
        call Delay_ms
        ;
        Return
     
LCD_WRITE_BLINK
        BCF   STATUS , RP0 ; Bank 0
        MOVLW LCD_ROW_LENGTH
        MOVWF line_ctr
        MOVLW LCD_ARRAY_START ; pointer to the first row
        MOVWF  FSR
;*****************************************************************
        ; Setting the DRAM Address
;*****************************************************************
        MOVLW 0x80
        MOVWF DRAM_ADDRESS ; Address = 0x00 (First Row)
DISP_ROW_1
        MOVFW DRAM_ADDRESS
        MOVWF LCD_DATA ; Address
        INCF DRAM_ADDRESS , 1 ; increment address for next data
        BCF PORTA , RS ; RS = 0
        BSF PORTA , EN ; EN = 1
        ; ; Delay
        MOVLW   LCD_CMD_DELAY
        MOVWF   ms
        call Delay_ms
        ;
        BCF PORTA , EN ; EN = 0
     
        ;
        MOVF INDF,W
        MOVWF LCD_DATA ; Display character
        BSF PORTA , RS ; RS = 1
        BSF PORTA , EN ; EN = 1
        ; ; Delay
        MOVLW   LCD_CMD_DELAY
        MOVWF   ms
        call Delay_ms
        ;
        BCF PORTA , EN ; EN = 0
     
        INCF FSR , 1
        DECFSZ line_ctr
        GOTO DISP_ROW_1
        ;
        ;
;*****************************************************************
 ; Setting the DRAM Address
;*****************************************************************
        MOVLW 0xC0
        MOVWF DRAM_ADDRESS ; Address = 0x00 (First Row)
        MOVLW LCD_ROW_LENGTH
        MOVWF line_ctr
        MOVLW 0x10
        ADDLW LCD_ARRAY_START ; pointer to the second row
        MOVWF  FSR
        ;
        ;
        Return
     
;******************************************************************
;CLEAR LCD
;******************************************************************
BLINK_LCD
        ; LCD CLEAR DISPLAY
        BCF PORTA , RS ; RS = 0
        MOVLW 0x01 ;
        MOVWF LCD_DATA ; Data = 0x01
        ; ; Delay
        MOVLW   LCD_CMD_DELAY
        MOVWF   ms
        call Delay_ms
        ;
        BSF PORTA , EN ; En = 1
        ; ; Delay
        MOVLW   LCD_CMD_DELAY
        MOVWF   ms
        call Delay_ms
        ;
        BCF PORTA , EN ; En = 0
        ; ; Delay
        MOVLW   LCD_BLINK_DELAY
        MOVWF   ms
        call Delay_ms
        ;
        call LCD_WRITE_BLINK
        ; ; Delay
        MOVLW   LCD_BLINK_DELAY
        MOVWF   ms
        call Delay_ms
        ;
        DECFSZ blink_ctr
        GOTO BLINK_LCD
     
     
     
        Return
     
   
 
    END
 
Last edited by a moderator:
You need to add a third option to your survey. 3 - completely ignore this post.

Mike.
Edit, removed unkind word.
 
We're not mind readers. Following someone else's train of thought is not easy. Ask specific, detailed questions and give us all possible background info. Don't just unload all your code on us and walk away.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top