;******************************* ;;8x8 Module.asm ;Test routine-2 Puts AAh on column 7 ; 13-6-2013 ;******************************* list p=12F629 radix dec include "p12f629.inc" errorlevel -302 ; Dont complain about BANK 1 Registers during assembly __CONFIG _MCLRE_OFF & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT ;Internal osc. ;_MCLRE_OFF - master clear must be off for gp3 to work as input pin ;**************************************************************** ; variables - names and files ;**************************************************************** Cblock 20h temp1 ;used in delay temp2 ;used in delay serial address _data endc ;**************************************************************** ;Equates ;**************************************************************** status equ 0x03 rp1 equ 0x06 rp0 equ 0x05 GPIO equ 0x05 status equ 03h option_reg equ 81h ; bits on GPIO pin7 equ 0 ;GP0 LED - flashes to indicate key number pin6 equ 1 ;GP1 Data to 8x8 Module pin5 equ 2 ;GP2 Chip Select pin4 equ 3 ;GP3 pin3 equ 4 ;GP4 Clock pin2 equ 5 ;GP5 4 switches ;bits rp0 equ 5 ;bit 5 of the status register ;**************************************************************** ;Beginning of program ;**************************************************************** org 0x00 nop nop nop nop nop SetUp bsf status, rp0 ;Bank 1 movlw b'11001000' ;Set TRIS GP0,1,2,4,5 out GP3 not used movwf TRISIO bcf status, rp0 ;bank 0 movlw 07h ;turn off Comparator ports movwf CMCON ;must be placed in bank 0 clrf GPIO ;Clear GPIO of junk goto Load ;**************************************************************** ;* Delays * ;**************************************************************** _1mS movlw 01h movwf temp2 decfsz temp1,f goto $-1 retlw 00 ;**************************************************************** ;* Sub Routines * ;**************************************************************** ;send 16 bits to 8x8 Module ;Manufacture address 1 - 8 for columns Load bcf gpio,2 ;open chip to receive address and data movlw 8 movwf serial ;load loop counter with 8 to transfer 8 bits movlw 07h movwf address ;to display column 7 rlf address,f ;move bit through carry rlf address,f ;move bit to bit0 position btfss address,0 ;these 3 instructions are very clever!!!! bcf gpio,1 ;to send LOW data bit btfsc address,0 ;see if the lowest bit is 0 or 1 bsf gpio,1 ;to send HIGH data bit rlf address,f ;put here to separate two gpio commands bsf gpio,4 ;clock HIGH call _1mS ;must have small delay between bsf and bcf bcf gpio,4 ;clock LOW to lock-in data bit decfsz serial,f goto $-9 ;send 8 bits DATA movlw 8 movwf serial ;load loop counter with 8 to transfer 8 bits movlw 0AAh movwf _data ;see the LEDs illuminate rlf _data,f ;move bit 7 to bit 0 position rlf _data,f btfss _data,0 bcf gpio,1 ;to send LOW data bit btfsc _data,0 ;see if the lowest bit is 0 or 1 bsf gpio,1 ;to send HIGH data bit rlf _data,f ;put here to separate two gpio commands bsf gpio,4 ;clock HIGH call _1mS bcf gpio,4 ;clock LOW to lock-in data bit decfsz serial,f goto $-9 bsf gpio,2 ;close chip ;create non-shutdown mode bcf gpio,2 ;open chip to receive address and data movlw 8 movwf serial ;load loop counter with 8 to transfer 8 bits movlw 0Ch ;0Ch accesses shutdown register movwf address rlf address,f ;move bit 7 to bit 0 position rlf address,f btfss address,0 ;these 3 instructions are very clever!!!! bcf gpio,1 ;to send LOW data bit btfsc address,0 ;see if the lowest bit is 0 or 1 bsf gpio,1 ;to send HIGH data bit rlf address,f ;put here to separate two gpio commands bsf gpio,4 ;clock HIGH call _1mS bcf gpio,4 ;clock LOW to lock-in data bit decfsz serial,f goto $-9 movlw 8 movwf serial ;load loop counter with 8 to transfer 8 bits movlw 7 ;1 is needed in data register for normal operation movwf _data ; rlf _data,f ;move bit 7 to bit 0 position rlf _data,f btfss _data,0 bcf gpio,1 ;to send LOW data bit btfsc _data,0 ;see if the lowest bit is 0 or 1 bsf gpio,1 ;to send HIGH data bit rlf _data,f ;put here to separate two gpio commands bsf gpio,4 ;clock HIGH call _1mS bcf gpio,4 ;clock LOW to lock-in data bit decfsz serial,f goto $-9 bsf gpio,2 ;close chip ;scan all columns bcf gpio,2 ;open chip to receive address and data movlw 8 movwf serial ;load loop counter with 8 to transfer 8 bits movlw 0Bh ;0Bh accesses scan-limit register movwf address rlf address,f ;move bit 7 to bit 0 position rlf address,f btfss address,0 ;these 3 instructions are very clever!!!! bcf gpio,1 ;to send LOW data bit btfsc address,0 ;see if the lowest bit is 0 or 1 bsf gpio,1 ;to send HIGH data bit rlf address,f ;put here to separate two gpio commands bsf gpio,4 ;clock HIGH call _1mS bcf gpio,4 ;clock LOW to lock-in data bit decfsz serial,f goto $-9 movlw 8 movwf serial ;load loop counter with 8 to transfer 8 bits movlw 7 ;7 is needed to scan 8 columns movwf _data rlf _data,1 ;move bit 7 to bit 0 position rlf _data,1 btfss _data,0 bcf gpio,1 ;to send LOW data bit btfsc _data,0 ;see if the lowest bit is 0 or 1 bsf gpio,1 ;to send HIGH data bit rlf _data,f ;put here to separate two gpio commands bsf gpio,4 ;clock HIGH call _1mS bcf gpio,4 ;clock LOW to lock-in data bit decfsz serial,f goto $-9 bsf gpio,2 ;close chip nop goto $-1 END