From d23fd4b43e08bfefc8fa2d6be90ac38c18a61958 Mon Sep 17 00:00:00 2001 From: Mark Neil Date: Tue, 11 Sep 2018 19:21:48 +0100 Subject: [PATCH 01/44] Creating Table_read branch --- Simple1.asm | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/Simple1.asm b/Simple1.asm index f7777b2e..d47fff58 100755 --- a/Simple1.asm +++ b/Simple1.asm @@ -2,20 +2,33 @@ code org 0x0 - goto start + goto setup org 0x100 ; Main code starts here at address 0x100 -start - movlw 0x0 - movwf TRISB, ACCESS ; Port C all outputs - bra test -loop movff 0x06, PORTB - incf 0x06, W, ACCESS -test movwf 0x06, ACCESS ; Test for end of loop condition - movlw 0x63 - cpfsgt 0x06, ACCESS - bra loop ; Not yet finished goto start of loop again - goto 0x0 ; Re-run program from start + ; ******* Programme FLASH read Setup Code **** +setup bcf EECON1, CFGS ; point to Flash program memory + bsf EECON1, EEPGD ; access Flash program memory + goto start + ; ******* My data and where to put it in RAM * +myTable data "This is just some data" + constant myArray=0x400 ; Address in RAM for data + constant counter=0x10 ; Address of counter variable + ; ******* Main programme ********************* +start lfsr FSR0, myArray ; Load FSR0 with address in RAM + movlw upper(myTable) ; address of data in PM + movwf TBLPTRU ; load upper bits to TBLPTRU + movlw high(myTable) ; address of data in PM + movwf TBLPTRH ; load high byte to TBLPTRH + movlw low(myTable) ; address of data in PM + movwf TBLPTRL ; load low byte to TBLPTRL + movlw .22 ; 22 bytes to read + movwf counter ; our counter register +loop tblrd*+ ; move one byte from PM to TABLAT, increment TBLPRT + movff TABLAT, POSTINC0 ; move read data from TABLAT to (FSR0), increment FSR0 + decfsz counter ; count down to zero + bra loop ; keep going until finished + goto 0 + end From c8c2b7203c8ae284d4b22e58e4fb3f601be431fa Mon Sep 17 00:00:00 2001 From: Mark Neil Date: Wed, 19 Sep 2018 13:37:14 +0100 Subject: [PATCH 02/44] Created UART_Hello_World branch --- Simple1.asm | 51 +++++++++++++++++++++++++----------- UART.asm | 38 +++++++++++++++++++++++++++ nbproject/configurations.xml | 1 + 3 files changed, 74 insertions(+), 16 deletions(-) mode change 100755 => 100644 Simple1.asm create mode 100644 UART.asm diff --git a/Simple1.asm b/Simple1.asm old mode 100755 new mode 100644 index d47fff58..de944e6e --- a/Simple1.asm +++ b/Simple1.asm @@ -1,20 +1,30 @@ #include p18f87k22.inc + + extern UART_Setup, UART_Transmit_Message ; external subroutines - code - org 0x0 +acs0 udata_acs ; reserve data space in access ram +counter res 1 ; reserve one byte for a counter variable +delay_count res 1 ; reserve one byte for counter in the delay routine + +tables udata 0x400 ; reserve data anywhere in RAM (here at 0x400) +myArray res 0x80 ; reserve 128 bytes for message data + +rst code 0 ; reset vector goto setup - - org 0x100 ; Main code starts here at address 0x100 - ; ******* Programme FLASH read Setup Code **** +pdata code ; a section of programme memory for storing data + ; ******* myTable, data in programme memory, and its length ***** +myTable data "Hello World!\n" ; message, plus carriage return + constant myTable_l=.13 ; length of data + +main code + ; ******* Programme FLASH read Setup Code *********************** setup bcf EECON1, CFGS ; point to Flash program memory bsf EECON1, EEPGD ; access Flash program memory + call UART_Setup ; setup UART goto start - ; ******* My data and where to put it in RAM * -myTable data "This is just some data" - constant myArray=0x400 ; Address in RAM for data - constant counter=0x10 ; Address of counter variable - ; ******* Main programme ********************* + + ; ******* Main programme **************************************** start lfsr FSR0, myArray ; Load FSR0 with address in RAM movlw upper(myTable) ; address of data in PM movwf TBLPTRU ; load upper bits to TBLPTRU @@ -22,13 +32,22 @@ start lfsr FSR0, myArray ; Load FSR0 with address in RAM movwf TBLPTRH ; load high byte to TBLPTRH movlw low(myTable) ; address of data in PM movwf TBLPTRL ; load low byte to TBLPTRL - movlw .22 ; 22 bytes to read + movlw myTable_l ; bytes to read movwf counter ; our counter register -loop tblrd*+ ; move one byte from PM to TABLAT, increment TBLPRT - movff TABLAT, POSTINC0 ; move read data from TABLAT to (FSR0), increment FSR0 +loop tblrd*+ ; one byte from PM to TABLAT, increment TBLPRT + movff TABLAT, POSTINC0; move data from TABLAT to (FSR0), inc FSR0 decfsz counter ; count down to zero bra loop ; keep going until finished - - goto 0 + + movlw myTable_l ; output message to UART + lfsr FSR2, myArray + call UART_Transmit_Message + + goto $ ; goto current line in code + + ; a delay subroutine if you need one, times around loop in delay_count +delay decfsz delay_count ; decrement until zero + bra delay + return - end + end \ No newline at end of file diff --git a/UART.asm b/UART.asm new file mode 100644 index 00000000..24dd96d2 --- /dev/null +++ b/UART.asm @@ -0,0 +1,38 @@ +#include p18f87k22.inc + + global UART_Setup, UART_Transmit_Message + +acs0 udata_acs ; named variables in access ram +UART_counter res 1 ; reserve 1 byte for variable UART_counter + +UART code + +UART_Setup + bsf RCSTA1, SPEN ; enable + bcf TXSTA1, SYNC ; synchronous + bcf TXSTA1, BRGH ; slow speed + bsf TXSTA1, TXEN ; enable transmit + bcf BAUDCON1, BRG16 ; 8-bit generator only + movlw .103 ; gives 9600 Baud rate (actually 9615) + movwf SPBRG1 + bsf TRISC, TX1 ; TX1 pin as output + return + +UART_Transmit_Message ; Message stored at FSR2, length stored in W + movwf UART_counter +UART_Loop_message + movf POSTINC2, W + call UART_Transmit_Byte + decfsz UART_counter + bra UART_Loop_message + return + +UART_Transmit_Byte ; Transmits byte stored in W + btfss PIR1,TX1IF ; TX1IF is set when TXREG1 is empty + bra UART_Transmit_Byte + movwf TXREG1 + return + + end + + diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index ad70b23a..38831578 100755 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -20,6 +20,7 @@ projectFiles="false"> Makefile + UART.asm Makefile From f2d6dee9ef05b9d18294fc8b5d18e43c9ca2c63b Mon Sep 17 00:00:00 2001 From: Mark Neil Date: Wed, 19 Sep 2018 14:09:22 +0100 Subject: [PATCH 03/44] Updated README.md --- README.md | 6 +++++- nbproject/configurations.xml | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b175f5e5..afe62296 100755 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ # Microprocessors Repository for Physics Year 3 microprocessors lab -A simple assembly program for PIC18 microprocessor, that counts to 100, putting the current count value out onto PORTB +A simple assembly program for PIC18 microprocessor + +Reads a table (message) from programme memory to data memory +Writes a message (the table) to UART + diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 38831578..9577c2e2 100755 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -14,13 +14,14 @@ projectFiles="true"> Simple1.asm config.asm + UART.asm Makefile - UART.asm + README.md Makefile From 679b49c1d28bc82d7fec8d48d7bb15a4324aea6b Mon Sep 17 00:00:00 2001 From: Mark Neil Date: Wed, 19 Sep 2018 14:23:41 +0100 Subject: [PATCH 04/44] Updated README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index afe62296..57dd621a 100755 --- a/README.md +++ b/README.md @@ -4,5 +4,5 @@ Repository for Physics Year 3 microprocessors lab A simple assembly program for PIC18 microprocessor Reads a table (message) from programme memory to data memory -Writes a message (the table) to UART - + +Initialises UART and writes a message (the table) to UART From 9df0e71f117067f705c360da5c45a5757dbf3744 Mon Sep 17 00:00:00 2001 From: maan Date: Mon, 24 Sep 2018 14:37:19 +0100 Subject: [PATCH 05/44] Updated for MPLAB IDE V5.05 --- nbproject/configurations.xml | 609 ++++++++++++++++++++++++++++++----- 1 file changed, 523 insertions(+), 86 deletions(-) diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 9577c2e2..c1f3834d 100755 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -1,86 +1,523 @@ - - - - - - - - - Simple1.asm - config.asm - UART.asm - - - Makefile - - README.md - - Makefile - - - - localhost - PIC18F87K22 - - - Simulator - MPASMWIN - 5.77 - 4 - - - - - - - - - - false - false - - - - - - - false - - false - - false - false - false - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + Simple1.asm + config.asm + UART.asm + + + Makefile + + README.md + + Makefile + + + + localhost + PIC18F87K22 + + + ICD3PlatformTool + MPASMWIN + 5.81 + 3 + + + + + + + + + + + + + false + false + + + + + + + false + + false + + false + false + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From cedb2ee6182dfc7e182cdf9de5d2305aac270809 Mon Sep 17 00:00:00 2001 From: Mark Neil Date: Tue, 20 Oct 2020 10:28:28 +0100 Subject: [PATCH 06/44] Compiles for V5.4 - memory not correct yet --- Simple1.asm | 53 -- UART.asm | 38 -- UART.s | 37 ++ config.asm => config.s | 6 +- main.s | 55 ++ nbproject/configurations.xml | 1133 ++++++++++++++++++---------------- nbproject/project.xml | 10 + 7 files changed, 715 insertions(+), 617 deletions(-) delete mode 100644 Simple1.asm delete mode 100644 UART.asm create mode 100644 UART.s rename config.asm => config.s (95%) create mode 100644 main.s diff --git a/Simple1.asm b/Simple1.asm deleted file mode 100644 index de944e6e..00000000 --- a/Simple1.asm +++ /dev/null @@ -1,53 +0,0 @@ - #include p18f87k22.inc - - extern UART_Setup, UART_Transmit_Message ; external subroutines - -acs0 udata_acs ; reserve data space in access ram -counter res 1 ; reserve one byte for a counter variable -delay_count res 1 ; reserve one byte for counter in the delay routine - -tables udata 0x400 ; reserve data anywhere in RAM (here at 0x400) -myArray res 0x80 ; reserve 128 bytes for message data - -rst code 0 ; reset vector - goto setup - -pdata code ; a section of programme memory for storing data - ; ******* myTable, data in programme memory, and its length ***** -myTable data "Hello World!\n" ; message, plus carriage return - constant myTable_l=.13 ; length of data - -main code - ; ******* Programme FLASH read Setup Code *********************** -setup bcf EECON1, CFGS ; point to Flash program memory - bsf EECON1, EEPGD ; access Flash program memory - call UART_Setup ; setup UART - goto start - - ; ******* Main programme **************************************** -start lfsr FSR0, myArray ; Load FSR0 with address in RAM - movlw upper(myTable) ; address of data in PM - movwf TBLPTRU ; load upper bits to TBLPTRU - movlw high(myTable) ; address of data in PM - movwf TBLPTRH ; load high byte to TBLPTRH - movlw low(myTable) ; address of data in PM - movwf TBLPTRL ; load low byte to TBLPTRL - movlw myTable_l ; bytes to read - movwf counter ; our counter register -loop tblrd*+ ; one byte from PM to TABLAT, increment TBLPRT - movff TABLAT, POSTINC0; move data from TABLAT to (FSR0), inc FSR0 - decfsz counter ; count down to zero - bra loop ; keep going until finished - - movlw myTable_l ; output message to UART - lfsr FSR2, myArray - call UART_Transmit_Message - - goto $ ; goto current line in code - - ; a delay subroutine if you need one, times around loop in delay_count -delay decfsz delay_count ; decrement until zero - bra delay - return - - end \ No newline at end of file diff --git a/UART.asm b/UART.asm deleted file mode 100644 index 24dd96d2..00000000 --- a/UART.asm +++ /dev/null @@ -1,38 +0,0 @@ -#include p18f87k22.inc - - global UART_Setup, UART_Transmit_Message - -acs0 udata_acs ; named variables in access ram -UART_counter res 1 ; reserve 1 byte for variable UART_counter - -UART code - -UART_Setup - bsf RCSTA1, SPEN ; enable - bcf TXSTA1, SYNC ; synchronous - bcf TXSTA1, BRGH ; slow speed - bsf TXSTA1, TXEN ; enable transmit - bcf BAUDCON1, BRG16 ; 8-bit generator only - movlw .103 ; gives 9600 Baud rate (actually 9615) - movwf SPBRG1 - bsf TRISC, TX1 ; TX1 pin as output - return - -UART_Transmit_Message ; Message stored at FSR2, length stored in W - movwf UART_counter -UART_Loop_message - movf POSTINC2, W - call UART_Transmit_Byte - decfsz UART_counter - bra UART_Loop_message - return - -UART_Transmit_Byte ; Transmits byte stored in W - btfss PIR1,TX1IF ; TX1IF is set when TXREG1 is empty - bra UART_Transmit_Byte - movwf TXREG1 - return - - end - - diff --git a/UART.s b/UART.s new file mode 100644 index 00000000..df00b76e --- /dev/null +++ b/UART.s @@ -0,0 +1,37 @@ +#include + +global UART_Setup, UART_Transmit_Message + +psect udata_acs ; reserve data space in access ram +UART_counter: ds 1 ; reserve 1 byte for variable UART_counter + +psect code +UART_Setup: + bsf SPEN ; enable + bcf SYNC ; synchronous + bcf BRGH ; slow speed + bsf TXEN ; enable transmit + bcf BRG16 ; 8-bit generator only + movlw 103 ; gives 9600 Baud rate (actually 9615) + movwf SPBRG1, A ; set baud rate + bsf TRISC6 ; TX1 pin is output on RC6 pin so must set TRISC6 to 1 + return + +UART_Transmit_Message: ; Message stored at FSR2, length stored in W + movwf UART_counter, A +UART_Loop_message: + movf POSTINC2, W, A + call UART_Transmit_Byte + decfsz UART_counter, A + bra UART_Loop_message + return + +UART_Transmit_Byte: ; Transmits byte stored in W + btfss TX1IF ; TX1IF is set when TXREG1 is empty + bra UART_Transmit_Byte + movwf TXREG1, A + return + + end + + diff --git a/config.asm b/config.s similarity index 95% rename from config.asm rename to config.s index 5c06fac2..02d79e5a 100755 --- a/config.asm +++ b/config.s @@ -2,7 +2,7 @@ ; Assembly source line config statements -#include "p18f87k22.inc" + #include ; CONFIG1L CONFIG RETEN = ON ; VREG Sleep Enable bit (Enabled) @@ -23,7 +23,7 @@ CONFIG BORPWR = ZPBORMV ; BORMV Power level (ZPBORMV instead of BORMV is selected) ; CONFIG2H - CONFIG WDTEN = SWDTDIS ; Watchdog Timer (WDT enabled in hardware; SWDTEN bit disabled) + CONFIG WDTEN = OFF ; Watchdog Timer (WDT enabled in hardware; SWDTEN bit disabled) CONFIG WDTPS = 1048576 ; Watchdog Postscaler (1:1048576) ; CONFIG3L @@ -36,7 +36,7 @@ ; CONFIG3H CONFIG CCP2MX = PORTC ; CCP2 Mux (RC1) CONFIG ECCPMX = PORTE ; ECCP Mux (Enhanced CCP1/3 [P1B/P1C/P3B/P3C] muxed with RE6/RE5/RE4/RE3) - CONFIG MSSPMSK = MSK7 ; MSSP address masking (7 Bit address masking mode) + CONFIG MSSPMSK = 1 ; MSSP address masking (7 Bit address masking mode) CONFIG MCLRE = ON ; Master Clear Enable (MCLR Enabled, RG5 Disabled) ; CONFIG4L diff --git a/main.s b/main.s new file mode 100644 index 00000000..c1e8b115 --- /dev/null +++ b/main.s @@ -0,0 +1,55 @@ +#include +#include + +extrn UART_Setup, UART_Transmit_Message ; external subroutines + +psect udata_acs ; reserve data space in access ram +counter: ds 1 ; reserve one byte for a counter variable +delay_count:ds 1 ; reserve one byte for counter in the delay routine + +psect udata_bank4 ; reserve data anywhere in RAM (here at 0x400) +myArray: ds 0x80 ; reserve 128 bytes for message data + +psect code, abs +main: org 0x0 + goto setup + + ; ******* myTable, data in programme memory, and its length ***** +myTable: + db 'H','e','l','l','o',' ','W','o','r','l','d','!','n' + ; message, plus carriage return + myTable_l EQU 13 ; length of data + align 2 + ; ******* Programme FLASH read Setup Code *********************** +setup: bcf CFGS ; point to Flash program memory + bsf EEPGD ; access Flash program memory + call UART_Setup ; setup UART + goto start + + ; ******* Main programme **************************************** +start: lfsr 0, myArray ; Load FSR0 with address in RAM + movlw low highword(myTable) ; address of data in PM + movwf TBLPTRU, A ; load upper bits to TBLPTRU + movlw high(myTable) ; address of data in PM + movwf TBLPTRH, A ; load high byte to TBLPTRH + movlw low(myTable) ; address of data in PM + movwf TBLPTRL, A ; load low byte to TBLPTRL + movlw myTable_l ; bytes to read + movwf counter, A ; our counter register +loop: tblrd*+ ; one byte from PM to TABLAT, increment TBLPRT + movff TABLAT, POSTINC0; move data from TABLAT to (FSR0), inc FSR0 + decfsz counter, A ; count down to zero + bra loop ; keep going until finished + + movlw myTable_l ; output message to UART + lfsr 2, myArray + call UART_Transmit_Message + + goto $ ; goto current line in code + + ; a delay subroutine if you need one, times around loop in delay_count +delay: decfsz delay_count, A ; decrement until zero + bra delay + return + + end main \ No newline at end of file diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index c1f3834d..935899fd 100755 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -1,523 +1,610 @@ - - - - - - - - - Simple1.asm - config.asm - UART.asm - - - Makefile - - README.md - - Makefile - - - - localhost - PIC18F87K22 - - - ICD3PlatformTool - MPASMWIN - 5.81 - 3 - - - - - - - - - - - - - false - false - - - - - - - false - - false - - false - false - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + config.s + main.s + UART.s + + + Makefile + + README.md + README.md + + Makefile + + + + localhost + PIC18F87K22 + + + Simulator + pic-as + 2.30 + 4 + + + + + + + + + + + + + + + false + false + + + + + + + false + + false + + false + false + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/project.xml b/nbproject/project.xml index cb688460..56b6f70e 100755 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -12,6 +12,16 @@ ISO-8859-1 + + + + default + 2 + + + + false + From 81fb230f5d4928d5741d628ee30e3c4472dd22ee Mon Sep 17 00:00:00 2001 From: Mark Neil Date: Wed, 21 Oct 2020 13:53:25 +0100 Subject: [PATCH 07/44] Updates for compatibility with pic-as --- UART.s => UART.S | 6 ++---- config.s => config.S | 0 main.s => main.S | 15 ++++++++------- nbproject/configurations.xml | 13 ++++++------- 4 files changed, 16 insertions(+), 18 deletions(-) rename UART.s => UART.S (94%) rename config.s => config.S (100%) rename main.s => main.S (93%) diff --git a/UART.s b/UART.S similarity index 94% rename from UART.s rename to UART.S index df00b76e..477b14bd 100644 --- a/UART.s +++ b/UART.S @@ -1,11 +1,11 @@ -#include +#include global UART_Setup, UART_Transmit_Message psect udata_acs ; reserve data space in access ram UART_counter: ds 1 ; reserve 1 byte for variable UART_counter -psect code +psect uart_code,class=CODE UART_Setup: bsf SPEN ; enable bcf SYNC ; synchronous @@ -32,6 +32,4 @@ UART_Transmit_Byte: ; Transmits byte stored in W movwf TXREG1, A return - end - diff --git a/config.s b/config.S similarity index 100% rename from config.s rename to config.S diff --git a/main.s b/main.S similarity index 93% rename from main.s rename to main.S index c1e8b115..fb1f4eb5 100644 --- a/main.s +++ b/main.S @@ -1,4 +1,3 @@ -#include #include extrn UART_Setup, UART_Transmit_Message ; external subroutines @@ -10,16 +9,18 @@ delay_count:ds 1 ; reserve one byte for counter in the delay routine psect udata_bank4 ; reserve data anywhere in RAM (here at 0x400) myArray: ds 0x80 ; reserve 128 bytes for message data -psect code, abs -main: org 0x0 - goto setup - +psect data ; ******* myTable, data in programme memory, and its length ***** myTable: - db 'H','e','l','l','o',' ','W','o','r','l','d','!','n' + db 'H','e','l','l','o',' ','W','o','r','l','d','!',0x0a ; message, plus carriage return myTable_l EQU 13 ; length of data align 2 + +psect code, abs +rst: org 0x0 + goto setup + ; ******* Programme FLASH read Setup Code *********************** setup: bcf CFGS ; point to Flash program memory bsf EEPGD ; access Flash program memory @@ -52,4 +53,4 @@ delay: decfsz delay_count, A ; decrement until zero bra delay return - end main \ No newline at end of file + end rst \ No newline at end of file diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 935899fd..60047adc 100755 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -12,17 +12,15 @@ - config.s - main.s - UART.s + main.S + UART.S + config.S Makefile - README.md - README.md Makefile @@ -32,7 +30,7 @@ PIC18F87K22 - Simulator + ICD3PlatformTool pic-as 2.30 4 @@ -74,6 +72,7 @@ value="Press to browse for a specific firmware version"/> + @@ -574,7 +573,6 @@ - @@ -588,6 +586,7 @@ + From 724f6cee912d7db02c24ef5c608312473c011941 Mon Sep 17 00:00:00 2001 From: Mark Neil Date: Wed, 21 Oct 2020 17:44:09 +0100 Subject: [PATCH 08/44] use position definition for register bit access --- UART.S | 3 ++- nbproject/configurations.xml | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/UART.S b/UART.S index 477b14bd..32bf8df9 100644 --- a/UART.S +++ b/UART.S @@ -14,7 +14,8 @@ UART_Setup: bcf BRG16 ; 8-bit generator only movlw 103 ; gives 9600 Baud rate (actually 9615) movwf SPBRG1, A ; set baud rate - bsf TRISC6 ; TX1 pin is output on RC6 pin so must set TRISC6 to 1 + bsf TRISC, PORTC_TX1_POSN, A ; TX1 pin is output on RC6 pin + ; must set TRISC6 to 1 return UART_Transmit_Message: ; Message stored at FSR2, length stored in W diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 60047adc..5834ed0a 100755 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -72,7 +72,6 @@ value="Press to browse for a specific firmware version"/> - From 897b471496795a5c1121e64b56357a06a37aaa24 Mon Sep 17 00:00:00 2001 From: Mark Neil Date: Thu, 22 Oct 2020 10:32:45 +0100 Subject: [PATCH 09/44] Created LCD_Hello_World_V5.4 branch --- LCD.S | 138 +++++++++++++++++++++++++++++++++++ main.S | 6 ++ nbproject/configurations.xml | 1 + 3 files changed, 145 insertions(+) create mode 100644 LCD.S diff --git a/LCD.S b/LCD.S new file mode 100644 index 00000000..ab1f2218 --- /dev/null +++ b/LCD.S @@ -0,0 +1,138 @@ +#include + +global LCD_Setup, LCD_Write_Message + +psect udata_acs ; named variables in access ram +LCD_cnt_l: ds 1 ; reserve 1 byte for variable LCD_cnt_l +LCD_cnt_h: ds 1 ; reserve 1 byte for variable LCD_cnt_h +LCD_cnt_ms: ds 1 ; reserve 1 byte for ms counter +LCD_tmp: ds 1 ; reserve 1 byte for temporary use +LCD_counter: ds 1 ; reserve 1 byte for counting through nessage + + LCD_E EQU 5 ; LCD enable bit + LCD_RS EQU 4 ; LCD register select bit + +psect lcd_code,class=CODE + +LCD_Setup: + clrf LATB, A + movlw 11000000B ; RB0:5 all outputs + movwf TRISB, A + movlw 40 + call LCD_delay_ms ; wait 40ms for LCD to start up properly + movlw 00110000B ; Function set 4-bit + call LCD_Send_Byte_I + movlw 10 ; wait 40us + call LCD_delay_x4us + movlw 00101000B ; 2 line display 5x8 dot characters + call LCD_Send_Byte_I + movlw 10 ; wait 40us + call LCD_delay_x4us + movlw 00101000B ; repeat, 2 line display 5x8 dot characters + call LCD_Send_Byte_I + movlw 10 ; wait 40us + call LCD_delay_x4us + movlw 00001111B ; display on, cursor on, blinking on + call LCD_Send_Byte_I + movlw 10 ; wait 40us + call LCD_delay_x4us + movlw 00000001B ; display clear + call LCD_Send_Byte_I + movlw 2 ; wait 2ms + call LCD_delay_ms + movlw 00000110B ; entry mode incr by 1 no shift + call LCD_Send_Byte_I + movlw 10 ; wait 40us + call LCD_delay_x4us + return + +LCD_Write_Message: ; Message stored at FSR2, length stored in W + movwf LCD_counter, A +LCD_Loop_message: + movf POSTINC2, W, A + call LCD_Send_Byte_D + decfsz LCD_counter, A + bra LCD_Loop_message + return + +LCD_Send_Byte_I: ; Transmits byte stored in W to instruction reg + movwf LCD_tmp, A + swapf LCD_tmp, W, A ; swap nibbles, high nibble goes first + andlw 0x0f ; select just low nibble + movwf LATB, A ; output data bits to LCD + bcf LATB, LCD_RS, A ; Instruction write clear RS bit + call LCD_Enable ; Pulse enable Bit + movf LCD_tmp, W, A ; swap nibbles, now do low nibble + andlw 0x0f ; select just low nibble + movwf LATB, A ; output data bits to LCD + bcf LATB, LCD_RS, A ; Instruction write clear RS bit + call LCD_Enable ; Pulse enable Bit + return + +LCD_Send_Byte_D: ; Transmits byte stored in W to data reg + movwf LCD_tmp, A + swapf LCD_tmp, W, A ; swap nibbles, high nibble goes first + andlw 0x0f ; select just low nibble + movwf LATB, A ; output data bits to LCD + bsf LATB, LCD_RS, A ; Data write set RS bit + call LCD_Enable ; Pulse enable Bit + movf LCD_tmp, W, A ; swap nibbles, now do low nibble + andlw 0x0f ; select just low nibble + movwf LATB, A ; output data bits to LCD + bsf LATB, LCD_RS, A ; Data write set RS bit + call LCD_Enable ; Pulse enable Bit + movlw 10 ; delay 40us + call LCD_delay_x4us + return + +LCD_Enable: ; pulse enable bit LCD_E for 500ns + nop + nop + nop + nop + nop + nop + nop + nop + bsf LATB, LCD_E, A ; Take enable high + nop + nop + nop + nop + nop + nop + nop + bcf LATB, LCD_E, A ; Writes data to LCD + return + +; ** a few delay routines below here as LCD timing can be quite critical **** +LCD_delay_ms: ; delay given in ms in W + movwf LCD_cnt_ms, A +lcdlp2: movlw 250 ; 1 ms delay + call LCD_delay_x4us + decfsz LCD_cnt_ms, A + bra lcdlp2 + return + +LCD_delay_x4us: ; delay given in chunks of 4 microsecond in W + movwf LCD_cnt_l, A ; now need to multiply by 16 + swapf LCD_cnt_l, F, A ; swap nibbles + movlw 0x0f + andwf LCD_cnt_l, W, A ; move low nibble to W + movwf LCD_cnt_h, A ; then to LCD_cnt_h + movlw 0xf0 + andwf LCD_cnt_l, F, A ; keep high nibble in LCD_cnt_l + call LCD_delay + return + +LCD_delay: ; delay routine 4 instruction loop == 250ns + movlw 0x00 ; W=0 +lcdlp1: decf LCD_cnt_l, F, A ; no carry when 0x00 -> 0xff + subwfb LCD_cnt_h, F, A ; no carry when 0x00 -> 0xff + bc lcdlp1 ; carry, then loop again + return ; carry reset so return + + + end + + diff --git a/main.S b/main.S index fb1f4eb5..ac15830d 100644 --- a/main.S +++ b/main.S @@ -1,6 +1,7 @@ #include extrn UART_Setup, UART_Transmit_Message ; external subroutines +extrn LCD_Setup, LCD_Write_Message psect udata_acs ; reserve data space in access ram counter: ds 1 ; reserve one byte for a counter variable @@ -25,6 +26,7 @@ rst: org 0x0 setup: bcf CFGS ; point to Flash program memory bsf EEPGD ; access Flash program memory call UART_Setup ; setup UART + call LCD_Setup ; setup UART goto start ; ******* Main programme **************************************** @@ -46,6 +48,10 @@ loop: tblrd*+ ; one byte from PM to TABLAT, increment TBLPRT lfsr 2, myArray call UART_Transmit_Message + movlw myTable_l ; output message to LCD + lfsr 2, myArray + call LCD_Write_Message + goto $ ; goto current line in code ; a delay subroutine if you need one, times around loop in delay_count diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 5834ed0a..dc4052c9 100755 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -15,6 +15,7 @@ main.S UART.S config.S + LCD.S Date: Mon, 26 Oct 2020 13:17:03 +0000 Subject: [PATCH 10/44] Don't send carriage return to LCD --- main.S | 1 + nbproject/configurations.xml | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/main.S b/main.S index ac15830d..dba4af8d 100644 --- a/main.S +++ b/main.S @@ -49,6 +49,7 @@ loop: tblrd*+ ; one byte from PM to TABLAT, increment TBLPRT call UART_Transmit_Message movlw myTable_l ; output message to LCD + addlw 0xff ; don't send the final carriage return to LCD lfsr 2, myArray call LCD_Write_Message diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index dc4052c9..4d2f30af 100755 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -22,6 +22,7 @@ projectFiles="false"> Makefile + README.md Makefile @@ -34,7 +35,7 @@ ICD3PlatformTool pic-as 2.30 - 4 + 3 From d10c58caa835c03b520180b2ad2bf787b14ae2ac Mon Sep 17 00:00:00 2001 From: Mark Neil Date: Wed, 3 Feb 2021 22:01:54 +0000 Subject: [PATCH 11/44] Changed extension to .s , added xc.inc everywhere --- LCD.S => LCD.s | 0 UART.S => UART.s | 0 config.S => config.s | 2 +- main.S => main.s | 0 nbproject/configurations.xml | 11 +++++------ 5 files changed, 6 insertions(+), 7 deletions(-) rename LCD.S => LCD.s (100%) rename UART.S => UART.s (100%) rename config.S => config.s (99%) rename main.S => main.s (100%) diff --git a/LCD.S b/LCD.s similarity index 100% rename from LCD.S rename to LCD.s diff --git a/UART.S b/UART.s similarity index 100% rename from UART.S rename to UART.s diff --git a/config.S b/config.s similarity index 99% rename from config.S rename to config.s index 02d79e5a..5fa7cad1 100755 --- a/config.S +++ b/config.s @@ -2,7 +2,7 @@ ; Assembly source line config statements - #include + #include ; CONFIG1L CONFIG RETEN = ON ; VREG Sleep Enable bit (Enabled) diff --git a/main.S b/main.s similarity index 100% rename from main.S rename to main.s diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 4d2f30af..06bd9f31 100755 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -12,17 +12,16 @@ - main.S - UART.S - config.S - LCD.S + config.s + main.s + UART.s + LCD.s Makefile - README.md Makefile @@ -35,7 +34,7 @@ ICD3PlatformTool pic-as 2.30 - 3 + 4 From 173b6cb4f5d54b9fbd4886343b07b43f10ac4028 Mon Sep 17 00:00:00 2001 From: Alyssa Gelmetti Date: Tue, 5 Mar 2024 11:48:22 +0000 Subject: [PATCH 12/44] Added Keypad_Read code --- Keypad.s | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 Keypad.s diff --git a/Keypad.s b/Keypad.s new file mode 100644 index 00000000..5ec29255 --- /dev/null +++ b/Keypad.s @@ -0,0 +1,81 @@ +#include + +global + +psect udata_acs ; reserve data space in access ram +Keypad_counter: ds 1 ; reserve 1 byte for variable Keypad_counter +row: ds 1 +col: ds 1 +button: ds 1 +cnt_ms: ds 1 ; reserve 1 byte for ms counter +cnt_l: ds 1 ; reserve 1 byte for variable cnt_l +cnt_h: ds 1 ; reserve 1 byte for variable cnt_h + + +psect keypad_code,class=CODE + +Keypad_Setup: + banksel PADCFG1 + bsf REPU + clrf LATE, A + banksel 0 + + movlw 0x0F + movwf TRISE, A + call delay_ms + + return + +Keypad_Read: + ;reading column + movlw 0x0F + movwf TRISE, A + call delay_ms + movff PORTE, col, A + + ;reading row + movlw 0xF0 + movwf TRISE, A + call delay_ms + movff PORTE, row, A + + ;finding button + movff row, WREG + addwf col, W, A + movwf button, A + call Keypad_Decode + return + +Keypad_Decode: + + +;Delay Routines +delay_ms: ; delay given in ms in W + movwf cnt_ms, A +lp2: movlw 250 ; 1 ms delay + call delay_x4us + decfsz cnt_ms, A + bra lp2 + return + +delay_x4us: ; delay given in chunks of 4 microsecond in W + movwf cnt_l, A ; now need to multiply by 16 + swapf cnt_l, F, A ; swap nibbles + movlw 0x0f + andwf cnt_l, W, A ; move low nibble to W + movwf cnt_h, A ; then to cnt_h + movlw 0xf0 + andwf cnt_l, F, A ; keep high nibble in cnt_l + call delay + return + +delay: ; delay routine 4 instruction loop == 250ns + movlw 0x00 ; W=0 +lp1: decf cnt_l, F, A ; no carry when 0x00 -> 0xff + subwfb cnt_h, F, A ; no carry when 0x00 -> 0xff + bc lp1 ; carry, then loop again + return ; carry reset so return + + + end + \ No newline at end of file From 5235463f78d48d5aa106fb4f6f5373cfafcc506f Mon Sep 17 00:00:00 2001 From: Alyssa Gelmetti Date: Wed, 6 Mar 2024 16:50:25 +0000 Subject: [PATCH 13/44] Added Keypad Decode code --- Keypad.s | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 102 insertions(+), 3 deletions(-) diff --git a/Keypad.s b/Keypad.s index 5ec29255..362dc52d 100644 --- a/Keypad.s +++ b/Keypad.s @@ -1,6 +1,6 @@ #include -global +global Keypad_Setup, Keypad_Read psect udata_acs ; reserve data space in access ram Keypad_counter: ds 1 ; reserve 1 byte for variable Keypad_counter @@ -43,11 +43,110 @@ Keypad_Read: movff row, WREG addwf col, W, A movwf button, A - call Keypad_Decode + call Error_Check return -Keypad_Decode: +Error_Check: + movlw 0x00 ;ascii code for null + cpfseq button, A + bra Decode_0 + retlw 0x00 + +Decode_0: + movlw 0x30 + cpfseq button, A + bra Decode_1 + retlw '0' + +Decode_1: + movlw 0x31 + cpfseq button, A + bra Decode_2 + retlw '1' + +Decode_2: + movlw 0x32 + cpfseq button, A + bra Decode_3 + retlw '2' + +Decode_3: + movlw 0x33 + cpfseq button, A + bra Decode_4 + retlw '3' + +Decode_4: + movlw 0x34 + cpfseq button, A + bra Decode_5 + retlw '4' + +Decode_5: + movlw 0x35 + cpfseq button, A + bra Decode_6 + retlw '5' + +Decode_6: + movlw 0x36 + cpfseq button, A + bra Decode_7 + retlw '6' + +Decode_7: + movlw 0x37 + cpfseq button, A + bra Decode_8 + retlw '7' + +Decode_8: + movlw 0x38 + cpfseq button, A + bra Decode_9 + retlw '8' + +Decode_9: + movlw 0x39 + cpfseq button, A + bra Decode_A + retlw '9' + +Decode_A: + movlw 0x41 + cpfseq button, A + bra Decode_B + retlw 'A' + +Decode_B: + movlw 0x42 + cpfseq button, A + bra Decode_C + retlw 'B' + +Decode_C: + movlw 0x43 + cpfseq button, A + bra Decode_D + retlw 'C' + +Decode_D: + movlw 0x44 + cpfseq button, A + bra Decode_E + retlw 'D' + +Decode_E: + movlw 0x45 + cpfseq button, A + bra Decode_F + retlw 'E' +Decode_F: + movlw 0x46 + cpfseq button, A + retlw 0xFF + retlw 'F' ;Delay Routines delay_ms: ; delay given in ms in W From b8fcaa72d46930c65732de894020c2cc837b1358 Mon Sep 17 00:00:00 2001 From: Alyssa Gelmetti Date: Wed, 6 Mar 2024 17:24:43 +0000 Subject: [PATCH 14/44] Sends character to LCD --- main.s | 45 +++++++++------------------------------------ 1 file changed, 9 insertions(+), 36 deletions(-) diff --git a/main.s b/main.s index dba4af8d..0228c213 100644 --- a/main.s +++ b/main.s @@ -1,23 +1,14 @@ #include extrn UART_Setup, UART_Transmit_Message ; external subroutines -extrn LCD_Setup, LCD_Write_Message +extrn LCD_Setup, LCD_Write_Message, LCD_Send_Byte_D +extrn Keypad_Setup, Keypad_Read psect udata_acs ; reserve data space in access ram counter: ds 1 ; reserve one byte for a counter variable delay_count:ds 1 ; reserve one byte for counter in the delay routine -psect udata_bank4 ; reserve data anywhere in RAM (here at 0x400) -myArray: ds 0x80 ; reserve 128 bytes for message data -psect data - ; ******* myTable, data in programme memory, and its length ***** -myTable: - db 'H','e','l','l','o',' ','W','o','r','l','d','!',0x0a - ; message, plus carriage return - myTable_l EQU 13 ; length of data - align 2 - psect code, abs rst: org 0x0 goto setup @@ -26,34 +17,16 @@ rst: org 0x0 setup: bcf CFGS ; point to Flash program memory bsf EEPGD ; access Flash program memory call UART_Setup ; setup UART - call LCD_Setup ; setup UART + call LCD_Setup ; setup LCD + call Keypad_Setup goto start ; ******* Main programme **************************************** -start: lfsr 0, myArray ; Load FSR0 with address in RAM - movlw low highword(myTable) ; address of data in PM - movwf TBLPTRU, A ; load upper bits to TBLPTRU - movlw high(myTable) ; address of data in PM - movwf TBLPTRH, A ; load high byte to TBLPTRH - movlw low(myTable) ; address of data in PM - movwf TBLPTRL, A ; load low byte to TBLPTRL - movlw myTable_l ; bytes to read - movwf counter, A ; our counter register -loop: tblrd*+ ; one byte from PM to TABLAT, increment TBLPRT - movff TABLAT, POSTINC0; move data from TABLAT to (FSR0), inc FSR0 - decfsz counter, A ; count down to zero - bra loop ; keep going until finished - - movlw myTable_l ; output message to UART - lfsr 2, myArray - call UART_Transmit_Message - - movlw myTable_l ; output message to LCD - addlw 0xff ; don't send the final carriage return to LCD - lfsr 2, myArray - call LCD_Write_Message - - goto $ ; goto current line in code +start: + call Keypad_Read ; finds button pressed and stores in WREG + call LCD_Send_Byte_D ; writes what is stored in W to LCD + call delay + goto start ; goto current line in code ; a delay subroutine if you need one, times around loop in delay_count delay: decfsz delay_count, A ; decrement until zero From c8c1d07426e5884596e844f1c5311e75bfe134c0 Mon Sep 17 00:00:00 2001 From: Alyssa Gelmetti Date: Wed, 6 Mar 2024 17:25:22 +0000 Subject: [PATCH 15/44] made LCD_Send_Byte_D global --- LCD.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LCD.s b/LCD.s index ab1f2218..44884a40 100644 --- a/LCD.s +++ b/LCD.s @@ -1,6 +1,6 @@ #include -global LCD_Setup, LCD_Write_Message +global LCD_Setup, LCD_Write_Message, LCD_Send_Byte_D psect udata_acs ; named variables in access ram LCD_cnt_l: ds 1 ; reserve 1 byte for variable LCD_cnt_l From 30e11c43ad8a5eb7b4b9966300a78c0e484b5d84 Mon Sep 17 00:00:00 2001 From: alyssamgel <107678941+alyssamgel@users.noreply.github.com> Date: Fri, 8 Mar 2024 09:54:23 +0000 Subject: [PATCH 16/44] Update configurations.xml --- nbproject/configurations.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 06bd9f31..7f98aafb 100755 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -16,6 +16,7 @@ main.s UART.s LCD.s + Keypad.s Date: Fri, 8 Mar 2024 10:19:38 +0000 Subject: [PATCH 17/44] Altered decode --- Keypad.s | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Keypad.s b/Keypad.s index 362dc52d..7173b572 100644 --- a/Keypad.s +++ b/Keypad.s @@ -53,97 +53,97 @@ Error_Check: retlw 0x00 Decode_0: - movlw 0x30 + movlw 0xBE cpfseq button, A bra Decode_1 retlw '0' Decode_1: - movlw 0x31 + movlw 0x77 cpfseq button, A bra Decode_2 retlw '1' Decode_2: - movlw 0x32 + movlw 0xB7 cpfseq button, A bra Decode_3 retlw '2' Decode_3: - movlw 0x33 + movlw 0xD7 cpfseq button, A bra Decode_4 retlw '3' Decode_4: - movlw 0x34 + movlw 0x7B cpfseq button, A bra Decode_5 retlw '4' Decode_5: - movlw 0x35 + movlw 0xBB cpfseq button, A bra Decode_6 retlw '5' Decode_6: - movlw 0x36 + movlw 0xDB cpfseq button, A bra Decode_7 retlw '6' Decode_7: - movlw 0x37 + movlw 0x7D cpfseq button, A bra Decode_8 retlw '7' Decode_8: - movlw 0x38 + movlw 0xBD cpfseq button, A bra Decode_9 retlw '8' Decode_9: - movlw 0x39 + movlw 0xDD cpfseq button, A bra Decode_A retlw '9' Decode_A: - movlw 0x41 + movlw 0x7E cpfseq button, A bra Decode_B retlw 'A' Decode_B: - movlw 0x42 + movlw 0xDE cpfseq button, A bra Decode_C retlw 'B' Decode_C: - movlw 0x43 + movlw 0xEE cpfseq button, A bra Decode_D retlw 'C' Decode_D: - movlw 0x44 + movlw 0xED cpfseq button, A bra Decode_E retlw 'D' Decode_E: - movlw 0x45 + movlw 0xEB cpfseq button, A bra Decode_F retlw 'E' Decode_F: - movlw 0x46 + movlw 0xE7 cpfseq button, A retlw 0xFF retlw 'F' From c26d72ec9fe5cf1dc0ef3ecb74a7915e5bc2c792 Mon Sep 17 00:00:00 2001 From: amg121 Date: Fri, 8 Mar 2024 11:52:55 +0000 Subject: [PATCH 18/44] IT WORKS --- Keypad.s | 52 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/Keypad.s b/Keypad.s index 7173b572..c6b265e0 100644 --- a/Keypad.s +++ b/Keypad.s @@ -22,27 +22,35 @@ Keypad_Setup: movlw 0x0F movwf TRISE, A + movlw 1 call delay_ms return Keypad_Read: - ;reading column - movlw 0x0F - movwf TRISE, A - call delay_ms - movff PORTE, col, A - - ;reading row - movlw 0xF0 + ; reading column + movlw 0x00 + movwf PORTE, A + movff PORTE, col + + ; reading row + movlw 0xF0 movwf TRISE, A + movlw 1 call delay_ms - movff PORTE, row, A + + movwf PORTE, A + movff PORTE, row + ;finding button movff row, WREG - addwf col, W, A + iorwf col, W, A movwf button, A + movlw 0x0F + movwf TRISE, A + + movff button, WREG call Error_Check return @@ -53,37 +61,37 @@ Error_Check: retlw 0x00 Decode_0: - movlw 0xBE + movlw 0x7D cpfseq button, A bra Decode_1 retlw '0' Decode_1: - movlw 0x77 + movlw 0xEE cpfseq button, A bra Decode_2 retlw '1' Decode_2: - movlw 0xB7 + movlw 0xED cpfseq button, A bra Decode_3 retlw '2' Decode_3: - movlw 0xD7 + movlw 0xEB cpfseq button, A bra Decode_4 retlw '3' Decode_4: - movlw 0x7B + movlw 0xDE cpfseq button, A bra Decode_5 retlw '4' Decode_5: - movlw 0xBB + movlw 0xDD cpfseq button, A bra Decode_6 retlw '5' @@ -95,7 +103,7 @@ Decode_6: retlw '6' Decode_7: - movlw 0x7D + movlw 0xBE cpfseq button, A bra Decode_8 retlw '7' @@ -107,7 +115,7 @@ Decode_8: retlw '8' Decode_9: - movlw 0xDD + movlw 0xBB cpfseq button, A bra Decode_A retlw '9' @@ -119,25 +127,25 @@ Decode_A: retlw 'A' Decode_B: - movlw 0xDE + movlw 0x7B cpfseq button, A bra Decode_C retlw 'B' Decode_C: - movlw 0xEE + movlw 0x77 cpfseq button, A bra Decode_D retlw 'C' Decode_D: - movlw 0xED + movlw 0xB7 cpfseq button, A bra Decode_E retlw 'D' Decode_E: - movlw 0xEB + movlw 0xD7 cpfseq button, A bra Decode_F retlw 'E' From ff3bdcc8c87d3534aed19d7f2e637a3887155a37 Mon Sep 17 00:00:00 2001 From: amg121 Date: Tue, 12 Mar 2024 10:53:35 +0000 Subject: [PATCH 19/44] added message set up --- main.s | 53 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/main.s b/main.s index 0228c213..1dc20f0a 100644 --- a/main.s +++ b/main.s @@ -1,13 +1,18 @@ #include +global inputangle + extrn UART_Setup, UART_Transmit_Message ; external subroutines -extrn LCD_Setup, LCD_Write_Message, LCD_Send_Byte_D +extrn LCD_Setup, LCD_Write_Message, LCD_Send_Byte_D, LCD_Clear extrn Keypad_Setup, Keypad_Read +extrn Input_Angle psect udata_acs ; reserve data space in access ram -counter: ds 1 ; reserve one byte for a counter variable -delay_count:ds 1 ; reserve one byte for counter in the delay routine - +counter: ds 1 ; reserve one byte for a counter variable +delay_count: ds 1 ; reserve one byte for counter in the delay routine +delay_count2: ds 1 +delay_count3: ds 1 +inputangle EQU 0xA0 psect code, abs rst: org 0x0 @@ -19,18 +24,54 @@ setup: bcf CFGS ; point to Flash program memory call UART_Setup ; setup UART call LCD_Setup ; setup LCD call Keypad_Setup + + call Input_Angle ; load message + + goto start ; ******* Main programme **************************************** start: + call LCD_Clear + movlw inputangle + movwf FSR2 + movlw 12 + call LCD_Write_Message + goto $ + +User_Input: call Keypad_Read ; finds button pressed and stores in WREG call LCD_Send_Byte_D ; writes what is stored in W to LCD - call delay + call delay_set goto start ; goto current line in code ; a delay subroutine if you need one, times around loop in delay_count -delay: decfsz delay_count, A ; decrement until zero +delay_set: + movlw 0xFF + movwf delay_count + bra delay + return + +delay: + movlw 0xFF + movwf delay_count2 + call delay_loop + decfsz delay_count bra delay return + +delay_loop: + movlw 0xFF + movwf delay_count3 + call delay_2 + decfsz delay_count2 + bra delay_loop + return + +delay_2: + decfsz delay_count3 + call delay_2 + return + end rst \ No newline at end of file From 8e78d2a07d860ebe451f18ab13a6f9f8b4d048aa Mon Sep 17 00:00:00 2001 From: amg121 Date: Tue, 12 Mar 2024 10:54:33 +0000 Subject: [PATCH 20/44] added messages.s --- nbproject/configurations.xml | 51 ++++++------------------------------ 1 file changed, 8 insertions(+), 43 deletions(-) diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 7f98aafb..8da1a64e 100755 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -17,6 +17,7 @@ UART.s LCD.s Keypad.s + Messages.s PIC18F87K22 - ICD3PlatformTool + pk4hybrid pic-as - 2.30 - 4 + 2.45 + 3 - + @@ -59,6 +60,7 @@ false + false false @@ -66,45 +68,6 @@ false false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -577,6 +540,7 @@ + @@ -597,6 +561,7 @@ + From 82c5f75e4dc2ba2155a3becd01794b42cdf69143 Mon Sep 17 00:00:00 2001 From: amg121 Date: Tue, 12 Mar 2024 10:54:54 +0000 Subject: [PATCH 21/44] contains messages to input onto LCD --- Messages.s | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Messages.s diff --git a/Messages.s b/Messages.s new file mode 100644 index 00000000..a7680ee2 --- /dev/null +++ b/Messages.s @@ -0,0 +1,57 @@ +#include + +global Input_Angle +extrn inputangle + +psect Messages, class = CODE + +Input_Angle: + movlw inputangle + movwf FSR0 + + movlw 'I' + movwf INDF0 + incf FSR0, F + + movlw 'n' + movwf INDF0 + incf FSR0, F + + movlw 'p' + movwf INDF0 + incf FSR0, F + + movlw 'u' + movwf INDF0 + incf FSR0, F + + movlw 't' + movwf INDF0 + incf FSR0, F + + movlw '' + movwf INDF0 + incf FSR0, F + + movlw 'A' + movwf INDF0 + incf FSR0, F + + movlw 'n' + movwf INDF0 + incf FSR0, F + + movlw 'g' + movwf INDF0 + incf FSR0, F + + movlw 'l' + movwf INDF0 + incf FSR0, F + + movlw 'e' + movwf INDF0 + incf FSR0, F + + return + From 98dd79a68bb912068220792f596e4166806fc066 Mon Sep 17 00:00:00 2001 From: amg121 Date: Tue, 12 Mar 2024 10:55:13 +0000 Subject: [PATCH 22/44] added LCD_Clear function --- LCD.s | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/LCD.s b/LCD.s index 44884a40..75d700fe 100644 --- a/LCD.s +++ b/LCD.s @@ -1,6 +1,6 @@ #include -global LCD_Setup, LCD_Write_Message, LCD_Send_Byte_D +global LCD_Setup, LCD_Write_Message, LCD_Send_Byte_D, LCD_delay_ms, LCD_Clear psect udata_acs ; named variables in access ram LCD_cnt_l: ds 1 ; reserve 1 byte for variable LCD_cnt_l @@ -11,7 +11,7 @@ LCD_counter: ds 1 ; reserve 1 byte for counting through nessage LCD_E EQU 5 ; LCD enable bit LCD_RS EQU 4 ; LCD register select bit - + psect lcd_code,class=CODE LCD_Setup: @@ -105,6 +105,12 @@ LCD_Enable: ; pulse enable bit LCD_E for 500ns bcf LATB, LCD_E, A ; Writes data to LCD return + +LCD_Clear: + movlw 00000001B + call LCD_Send_Byte_I + return + ; ** a few delay routines below here as LCD timing can be quite critical **** LCD_delay_ms: ; delay given in ms in W movwf LCD_cnt_ms, A From a47e5cc4202191274524b42fba09ce22ffb56733 Mon Sep 17 00:00:00 2001 From: amg121 Date: Tue, 12 Mar 2024 12:23:17 +0000 Subject: [PATCH 23/44] --- Keypad.s | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Keypad.s b/Keypad.s index c6b265e0..5a020bc0 100644 --- a/Keypad.s +++ b/Keypad.s @@ -1,6 +1,6 @@ #include -global Keypad_Setup, Keypad_Read +global Keypad_Setup, Keypad_Read, delay_ms psect udata_acs ; reserve data space in access ram Keypad_counter: ds 1 ; reserve 1 byte for variable Keypad_counter @@ -32,6 +32,8 @@ Keypad_Read: movlw 0x00 movwf PORTE, A movff PORTE, col + movlw 1 + call delay_ms ; reading row movlw 0xF0 From 4e3a7d31c0e3e8f3730a549979c29f985745bb8b Mon Sep 17 00:00:00 2001 From: amg121 Date: Tue, 12 Mar 2024 12:23:29 +0000 Subject: [PATCH 24/44] --- Messages.s | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Messages.s b/Messages.s index a7680ee2..a46d9a7d 100644 --- a/Messages.s +++ b/Messages.s @@ -7,7 +7,7 @@ psect Messages, class = CODE Input_Angle: movlw inputangle - movwf FSR0 + movwf FSR0 ; points to start of message movlw 'I' movwf INDF0 @@ -29,7 +29,7 @@ Input_Angle: movwf INDF0 incf FSR0, F - movlw '' + movlw ' ' movwf INDF0 incf FSR0, F @@ -52,6 +52,5 @@ Input_Angle: movlw 'e' movwf INDF0 incf FSR0, F - return From e723469a4046a1d0479fb84e31adef8ede7316e9 Mon Sep 17 00:00:00 2001 From: amg121 Date: Tue, 12 Mar 2024 12:23:47 +0000 Subject: [PATCH 25/44] Added code to read single digit --- main.s | 64 +++++++++++++++++++++++++--------------------------------- 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/main.s b/main.s index 1dc20f0a..88caaf7b 100644 --- a/main.s +++ b/main.s @@ -4,15 +4,19 @@ global inputangle extrn UART_Setup, UART_Transmit_Message ; external subroutines extrn LCD_Setup, LCD_Write_Message, LCD_Send_Byte_D, LCD_Clear -extrn Keypad_Setup, Keypad_Read +extrn Keypad_Setup, Keypad_Read, delay_ms extrn Input_Angle psect udata_acs ; reserve data space in access ram counter: ds 1 ; reserve one byte for a counter variable delay_count: ds 1 ; reserve one byte for counter in the delay routine -delay_count2: ds 1 -delay_count3: ds 1 -inputangle EQU 0xA0 +input: ds 1 +input_address EQU 0xB0 + + inputangle EQU 0xA0 + +psect udata_bank4 ; reserve data anywhere in RAM +myArray: ds 0x80 psect code, abs rst: org 0x0 @@ -27,7 +31,6 @@ setup: bcf CFGS ; point to Flash program memory call Input_Angle ; load message - goto start ; ******* Main programme **************************************** @@ -35,43 +38,30 @@ start: call LCD_Clear movlw inputangle movwf FSR2 - movlw 12 + movlw 11 call LCD_Write_Message - goto $ - -User_Input: - call Keypad_Read ; finds button pressed and stores in WREG - call LCD_Send_Byte_D ; writes what is stored in W to LCD - call delay_set - goto start ; goto current line in code - - ; a delay subroutine if you need one, times around loop in delay_count -delay_set: movlw 0xFF - movwf delay_count - bra delay - return + call delay_ms + goto User_Input -delay: - movlw 0xFF - movwf delay_count2 - call delay_loop - decfsz delay_count - bra delay - return +User_Input: + movlw input_address + movwf FSR0 + + call Keypad_Read ; finds button pressed and stores in WREG + movwf input + movwf PORTD -delay_loop: movlw 0xFF - movwf delay_count3 - call delay_2 - decfsz delay_count2 - bra delay_loop - return + call delay_ms -delay_2: - decfsz delay_count3 - call delay_2 - return + movlw 0x00 + cpfslt input + bra User_Input + movlw input + call LCD_Send_Byte_D ; writes what is stored in W to LCD + goto $ - end rst \ No newline at end of file + end rst + \ No newline at end of file From 1a8f720369a73f4886151f5d9c21077575091d8a Mon Sep 17 00:00:00 2001 From: amg121 Date: Thu, 14 Mar 2024 11:42:33 +0000 Subject: [PATCH 26/44] Added ':' --- Messages.s | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Messages.s b/Messages.s index a46d9a7d..9d28c5f3 100644 --- a/Messages.s +++ b/Messages.s @@ -52,5 +52,9 @@ Input_Angle: movlw 'e' movwf INDF0 incf FSR0, F + + movlw ':' + movwf INDF0 + return From 259ad35254de7c8a2d3924eaa83a575c87b079b7 Mon Sep 17 00:00:00 2001 From: amg121 Date: Thu, 14 Mar 2024 11:43:05 +0000 Subject: [PATCH 27/44] Added function to write to second line of screen --- LCD.s | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/LCD.s b/LCD.s index 75d700fe..98bff782 100644 --- a/LCD.s +++ b/LCD.s @@ -1,6 +1,6 @@ #include -global LCD_Setup, LCD_Write_Message, LCD_Send_Byte_D, LCD_delay_ms, LCD_Clear +global LCD_Setup, LCD_Write_Message, LCD_Clear, Second_Line psect udata_acs ; named variables in access ram LCD_cnt_l: ds 1 ; reserve 1 byte for variable LCD_cnt_l @@ -111,6 +111,13 @@ LCD_Clear: call LCD_Send_Byte_I return +Second_Line: + movlw 0011000000B + call LCD_Send_Byte_I + movwf 10 + call LCD_delay_ms + return + ; ** a few delay routines below here as LCD timing can be quite critical **** LCD_delay_ms: ; delay given in ms in W movwf LCD_cnt_ms, A From 1d320d4eff32252e35b671dea951e7082f9cacec Mon Sep 17 00:00:00 2001 From: amg121 Date: Thu, 14 Mar 2024 11:43:28 +0000 Subject: [PATCH 28/44] Commented out general decode --- Keypad.s | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Keypad.s b/Keypad.s index 5a020bc0..96ea4193 100644 --- a/Keypad.s +++ b/Keypad.s @@ -1,6 +1,6 @@ #include -global Keypad_Setup, Keypad_Read, delay_ms +global Keypad_Setup, Keypad_Read psect udata_acs ; reserve data space in access ram Keypad_counter: ds 1 ; reserve 1 byte for variable Keypad_counter @@ -53,14 +53,14 @@ Keypad_Read: movwf TRISE, A movff button, WREG - call Error_Check + ;call Error_Check return Error_Check: - movlw 0x00 ;ascii code for null + movlw 0xFF ;ascii code for null cpfseq button, A bra Decode_0 - retlw 0x00 + retlw 0xFF Decode_0: movlw 0x7D From d66fd1c06ef9961b143b17ce97f65a4993b97bb8 Mon Sep 17 00:00:00 2001 From: amg121 Date: Thu, 14 Mar 2024 11:43:47 +0000 Subject: [PATCH 29/44] Added input code --- main.s | 71 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/main.s b/main.s index 88caaf7b..ce60a0ac 100644 --- a/main.s +++ b/main.s @@ -1,19 +1,22 @@ #include -global inputangle +global inputangle, delay_ms, input_address_1, input_address_2 extrn UART_Setup, UART_Transmit_Message ; external subroutines -extrn LCD_Setup, LCD_Write_Message, LCD_Send_Byte_D, LCD_Clear -extrn Keypad_Setup, Keypad_Read, delay_ms +extrn LCD_Setup, LCD_Write_Message, LCD_Clear, Second_Line +extrn Keypad_Setup, Keypad_Read extrn Input_Angle +extrn User_Input_Setup psect udata_acs ; reserve data space in access ram counter: ds 1 ; reserve one byte for a counter variable -delay_count: ds 1 ; reserve one byte for counter in the delay routine -input: ds 1 -input_address EQU 0xB0 - - inputangle EQU 0xA0 +cnt_ms: ds 1 ; reserve 1 byte for ms counter +cnt_l: ds 1 ; reserve 1 byte for variable cnt_l +cnt_h: ds 1 ; reserve 1 byte for variable cnt_h + + input_address_1 EQU 0xB0 + input_address_2 EQU 0xC0 + inputangle EQU 0xA0 psect udata_bank4 ; reserve data anywhere in RAM myArray: ds 0x80 @@ -35,33 +38,43 @@ setup: bcf CFGS ; point to Flash program memory ; ******* Main programme **************************************** start: - call LCD_Clear movlw inputangle movwf FSR2 - movlw 11 + movlw 12 call LCD_Write_Message - movlw 0xFF call delay_ms - goto User_Input - -User_Input: - movlw input_address - movwf FSR0 - - call Keypad_Read ; finds button pressed and stores in WREG - movwf input - movwf PORTD - - movlw 0xFF call delay_ms - - movlw 0x00 - cpfslt input - bra User_Input + call delay_ms - movlw input - call LCD_Send_Byte_D ; writes what is stored in W to LCD + call User_Input_Setup goto $ + +;Delay Routines +delay_ms: ; delay given in ms in W + movwf cnt_ms, A +lp2: movlw 0xFF + call delay_x4us + decfsz cnt_ms, A + bra lp2 + return + +delay_x4us: ; delay given in chunks of 4 microsecond in W + movwf cnt_l, A ; now need to multiply by 16 + swapf cnt_l, F, A ; swap nibbles + movlw 0x0f + andwf cnt_l, W, A ; move low nibble to W + movwf cnt_h, A ; then to cnt_h + movlw 0xf0 + andwf cnt_l, F, A ; keep high nibble in cnt_l + call delay + return + +delay: ; delay routine 4 instruction loop == 250ns + movlw 0x00 ; W=0 +lp1: decf cnt_l, F, A ; no carry when 0x00 -> 0xff + subwfb cnt_h, F, A ; no carry when 0x00 -> 0xff + bc lp1 ; carry, then loop again + return ; carry reset so return + end rst - \ No newline at end of file From 5fa7400fa39daa5703b76be96353272c562f5863 Mon Sep 17 00:00:00 2001 From: amg121 Date: Thu, 14 Mar 2024 11:44:10 +0000 Subject: [PATCH 30/44] Module for inputting with keypad --- Digit_Input.s | 284 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 284 insertions(+) create mode 100644 Digit_Input.s diff --git a/Digit_Input.s b/Digit_Input.s new file mode 100644 index 00000000..45f125aa --- /dev/null +++ b/Digit_Input.s @@ -0,0 +1,284 @@ +#include + +global User_Input_Setup +extrn Keypad_Setup, Keypad_Read +extrn LCD_Setup, LCD_Write_Message, LCD_Clear, Second_Line +extrn input_address_1, input_address_2, delay_ms + +psect udata_acs ; reserve data space in access ram +digit_counter: ds 1 +d1: ds 1 +d2: ds 1 +input_1: ds 1 +input_2: ds 1 +before_dec: ds 1 + +psect udata_bank4 ; reserve data anywhere in RAM +myArray: ds 0x80 + +psect input_code, class=CODE + +User_Input_Setup: + movlw 2 + movwf digit_counter ; setting the number of digits to be inputted as 2 + + call User_Input_1 + call User_Input_2 + call delay_ms + + movff input_1, WREG + addwf input_2, W + movwf before_dec + + call delay_ms + call delay_ms + call delay_ms + + return + +User_Input_1: + movlw input_address_1 + movwf FSR0 + + call Keypad_Read ; finds button pressed and stores in WREG + call Decode_Input_1 + movwf input_1 + + movlw 0xFF + call delay_ms + + movlw 0xFF + cpfslt input_1 + bra User_Input_1 + decf digit_counter + + call Second_Line + movlw input_address_1 + movwf FSR2 + movlw 1 + call LCD_Write_Message + + return + +User_Input_2: + movlw input_address_2 + movwf FSR0 + + call Keypad_Read ; finds button pressed and stores in WREG + call Decode_Input_2 + movwf input_2 + + movlw 0xFF + call delay_ms + + movlw 0xFF + cpfslt input_2 + bra User_Input_2 + decf digit_counter + + movlw input_address_2 + movwf FSR2 + movlw 1 + call LCD_Write_Message + + return + +Decode_Input_1: + movwf d1, A +Error_Check_1: + movlw 0xFF ;ascii code for null + cpfseq d1, A + bra Decode_0_1 + retlw 0xFF + +Decode_0_1: + movlw 0x7D + cpfseq d1, A + bra Decode_1_1 + movlw '0' + movwf INDF0 + incf FSR0 + retlw 0 + +Decode_1_1: + movlw 0xEE + cpfseq d1, A + bra Decode_2_1 + movlw '1' + movwf INDF0 + incf FSR0 + retlw 10 + +Decode_2_1: + movlw 0xED + cpfseq d1, A + bra Decode_3_1 + movlw '2' + movwf INDF0 + incf FSR0 + retlw 20 + +Decode_3_1: + movlw 0xEB + cpfseq d1, A + bra Decode_4_1 + movlw '3' + movwf INDF0 + incf FSR0 + retlw 30 + +Decode_4_1: + movlw 0xDE + cpfseq d1, A + bra Decode_5_1 + movlw '4' + movwf INDF0 + incf FSR0 + retlw 40 + +Decode_5_1: + movlw 0xDD + cpfseq d1, A + bra Decode_6_1 + movlw '5' + movwf INDF0 + incf FSR0 + retlw 50 + +Decode_6_1: + movlw 0xDB + cpfseq d1, A + bra Decode_7_1 + movlw '6' + movwf INDF0 + incf FSR0 + retlw 60 + +Decode_7_1: + movlw 0xBE + cpfseq d1, A + bra Decode_8_1 + movlw '7' + movwf INDF0 + incf FSR0 + retlw 70 + +Decode_8_1: + movlw 0xBD + cpfseq d1, A + bra Decode_9_1 + movlw '8' + movwf INDF0 + incf FSR0 + retlw 80 + +Decode_9_1: + movlw 0xBB + cpfseq d1, A + retlw 0xFF + movlw '9' + movwf INDF0 + incf FSR0 + retlw 90 + + +Decode_Input_2: + movwf d2, A +Error_Check_2: + movlw 0xFF ;ascii code for null + cpfseq d2, A + bra Decode_0_2 + retlw 0xFF + +Decode_0_2: + movlw 0x7D + cpfseq d2, A + bra Decode_1_2 + movlw '0' + movwf INDF0 + incf FSR0 + retlw 0 + +Decode_1_2: + movlw 0xEE + cpfseq d2, A + bra Decode_2_2 + movlw '1' + movwf INDF0 + incf FSR0 + retlw 1 + +Decode_2_2: + movlw 0xED + cpfseq d2, A + bra Decode_3_2 + movlw '2' + movwf INDF0 + incf FSR0 + retlw 2 + +Decode_3_2: + movlw 0xEB + cpfseq d2, A + bra Decode_4_2 + movlw '3' + movwf INDF0 + incf FSR0 + retlw 3 + +Decode_4_2: + movlw 0xDE + cpfseq d2, A + bra Decode_5_2 + movlw '4' + movwf INDF0 + incf FSR0 + retlw 4 + +Decode_5_2: + movlw 0xDD + cpfseq d2, A + bra Decode_6_2 + movlw '5' + movwf INDF0 + incf FSR0 + retlw 5 + +Decode_6_2: + movlw 0xDB + cpfseq d2, A + bra Decode_7_2 + movlw '6' + movwf INDF0 + incf FSR0 + retlw 6 + +Decode_7_2: + movlw 0xBE + cpfseq d2, A + bra Decode_8_2 + movlw '7' + movwf INDF0 + incf FSR0 + retlw 7 + +Decode_8_2: + movlw 0xBD + cpfseq d2, A + bra Decode_9_2 + movlw '8' + movwf INDF0 + incf FSR0 + retlw 8 + +Decode_9_2: + movlw 0xBB + cpfseq d2, A + retlw 0xFF + movlw '9' + movwf INDF0 + incf FSR0 + retlw 9 + + + \ No newline at end of file From b32eeda87453d61fabb9b63abe463d272fc1b64e Mon Sep 17 00:00:00 2001 From: amg121 Date: Thu, 14 Mar 2024 11:44:24 +0000 Subject: [PATCH 31/44] added new module --- nbproject/configurations.xml | 133 +++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index 8da1a64e..dcbd0e3b 100755 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -18,6 +18,7 @@ LCD.s Keypad.s Messages.s + Digit_Input.s + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -570,6 +637,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 318879cabf9fe754508dc29bbeeb93eaed0cc22b Mon Sep 17 00:00:00 2001 From: amg121 Date: Thu, 14 Mar 2024 11:54:40 +0000 Subject: [PATCH 32/44] added comments --- main.s | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.s b/main.s index ce60a0ac..fad5b959 100644 --- a/main.s +++ b/main.s @@ -38,15 +38,15 @@ setup: bcf CFGS ; point to Flash program memory ; ******* Main programme **************************************** start: - movlw inputangle + movlw inputangle ; Writes 'input angle' messge movwf FSR2 movlw 12 - call LCD_Write_Message + call LCD_Write_Message call delay_ms call delay_ms call delay_ms - call User_Input_Setup + call User_Input_Setup ; Waits for user input (8-bit/2-digits) goto $ From ebdc13a94842f00f813170c17ddb3c7b0dae1363 Mon Sep 17 00:00:00 2001 From: amg121 Date: Thu, 14 Mar 2024 11:58:02 +0000 Subject: [PATCH 33/44] added comments --- main.s | 54 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/main.s b/main.s index fad5b959..8a6a9513 100644 --- a/main.s +++ b/main.s @@ -8,17 +8,17 @@ extrn Keypad_Setup, Keypad_Read extrn Input_Angle extrn User_Input_Setup -psect udata_acs ; reserve data space in access ram -counter: ds 1 ; reserve one byte for a counter variable -cnt_ms: ds 1 ; reserve 1 byte for ms counter -cnt_l: ds 1 ; reserve 1 byte for variable cnt_l -cnt_h: ds 1 ; reserve 1 byte for variable cnt_h +psect udata_acs ; reserve data space in access ram +counter: ds 1 +cnt_ms: ds 1 ; reserve 1 byte for ms counter +cnt_l: ds 1 ; reserve 1 byte for variable cnt_l +cnt_h: ds 1 ; reserve 1 byte for variable cnt_h input_address_1 EQU 0xB0 input_address_2 EQU 0xC0 inputangle EQU 0xA0 -psect udata_bank4 ; reserve data anywhere in RAM +psect udata_bank4 ; reserve data anywhere in RAM myArray: ds 0x80 psect code, abs @@ -26,19 +26,19 @@ rst: org 0x0 goto setup ; ******* Programme FLASH read Setup Code *********************** -setup: bcf CFGS ; point to Flash program memory - bsf EEPGD ; access Flash program memory - call UART_Setup ; setup UART - call LCD_Setup ; setup LCD +setup: bcf CFGS ; point to Flash program memory + bsf EEPGD ; access Flash program memory + call UART_Setup ; setup UART + call LCD_Setup ; setup LCD call Keypad_Setup - call Input_Angle ; load message + call Input_Angle ; load message goto start ; ******* Main programme **************************************** start: - movlw inputangle ; Writes 'input angle' messge + movlw inputangle ; Writes 'input angle' messge movwf FSR2 movlw 12 call LCD_Write_Message @@ -46,12 +46,13 @@ start: call delay_ms call delay_ms - call User_Input_Setup ; Waits for user input (8-bit/2-digits) + call User_Input_Setup ; Waits for user input + ; (8-bit/2-digits) goto $ ;Delay Routines -delay_ms: ; delay given in ms in W +delay_ms: ; delay given in ms in W movwf cnt_ms, A lp2: movlw 0xFF call delay_x4us @@ -59,22 +60,23 @@ lp2: movlw 0xFF bra lp2 return -delay_x4us: ; delay given in chunks of 4 microsecond in W - movwf cnt_l, A ; now need to multiply by 16 - swapf cnt_l, F, A ; swap nibbles +delay_x4us: ; delay given in chunks of + ; 4 microsecond in W + movwf cnt_l, A ; now need to multiply by 16 + swapf cnt_l, F, A ; swap nibbles movlw 0x0f - andwf cnt_l, W, A ; move low nibble to W - movwf cnt_h, A ; then to cnt_h + andwf cnt_l, W, A ; move low nibble to W + movwf cnt_h, A ; then to cnt_h movlw 0xf0 - andwf cnt_l, F, A ; keep high nibble in cnt_l + andwf cnt_l, F, A ; keep high nibble in cnt_l call delay return -delay: ; delay routine 4 instruction loop == 250ns - movlw 0x00 ; W=0 -lp1: decf cnt_l, F, A ; no carry when 0x00 -> 0xff - subwfb cnt_h, F, A ; no carry when 0x00 -> 0xff - bc lp1 ; carry, then loop again - return ; carry reset so return +delay: ; delay routine 4 instruction loop + movlw 0x00 ; W=0 +lp1: decf cnt_l, F, A ; no carry when 0x00 -> 0xff + subwfb cnt_h, F, A ; no carry when 0x00 -> 0xff + bc lp1 ; carry, then loop again + return ; carry reset so return end rst From 2f5402a1fbe3338aa499a8987dbf580851008ff4 Mon Sep 17 00:00:00 2001 From: amg121 Date: Thu, 14 Mar 2024 11:58:44 +0000 Subject: [PATCH 34/44] added comments --- LCD.s | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/LCD.s b/LCD.s index 98bff782..a731f84e 100644 --- a/LCD.s +++ b/LCD.s @@ -85,7 +85,7 @@ LCD_Send_Byte_D: ; Transmits byte stored in W to data reg call LCD_delay_x4us return -LCD_Enable: ; pulse enable bit LCD_E for 500ns +LCD_Enable: ; pulse enable bit LCD_E for 500ns nop nop nop @@ -107,21 +107,21 @@ LCD_Enable: ; pulse enable bit LCD_E for 500ns LCD_Clear: - movlw 00000001B + movlw 00000001B ; Clears LCD screen call LCD_Send_Byte_I return Second_Line: - movlw 0011000000B + movlw 0011000000B ; Points to bottom row of LCD screen call LCD_Send_Byte_I movwf 10 call LCD_delay_ms return ; ** a few delay routines below here as LCD timing can be quite critical **** -LCD_delay_ms: ; delay given in ms in W +LCD_delay_ms: ; delay given in ms in W movwf LCD_cnt_ms, A -lcdlp2: movlw 250 ; 1 ms delay +lcdlp2: movlw 250 ; 1 ms delay call LCD_delay_x4us decfsz LCD_cnt_ms, A bra lcdlp2 From 79d14e8c394550c97cc5417f2671532fe77f03b2 Mon Sep 17 00:00:00 2001 From: amg121 Date: Thu, 14 Mar 2024 11:58:56 +0000 Subject: [PATCH 35/44] added comments --- Digit_Input.s | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/Digit_Input.s b/Digit_Input.s index 45f125aa..9299b7d2 100644 --- a/Digit_Input.s +++ b/Digit_Input.s @@ -5,7 +5,7 @@ extrn Keypad_Setup, Keypad_Read extrn LCD_Setup, LCD_Write_Message, LCD_Clear, Second_Line extrn input_address_1, input_address_2, delay_ms -psect udata_acs ; reserve data space in access ram +psect udata_acs ; reserve data space in access ram digit_counter: ds 1 d1: ds 1 d2: ds 1 @@ -13,20 +13,22 @@ input_1: ds 1 input_2: ds 1 before_dec: ds 1 -psect udata_bank4 ; reserve data anywhere in RAM +psect udata_bank4 ; reserve data anywhere in RAM myArray: ds 0x80 psect input_code, class=CODE User_Input_Setup: movlw 2 - movwf digit_counter ; setting the number of digits to be inputted as 2 + movwf digit_counter ; setting the number of digits to be + ; inputted as 2 call User_Input_1 call User_Input_2 call delay_ms - movff input_1, WREG + movff input_1, WREG ; adding together the two digits to + ; create one 8 bit number addwf input_2, W movwf before_dec @@ -37,22 +39,22 @@ User_Input_Setup: return User_Input_1: - movlw input_address_1 + movlw input_address_1 ; address to store first digit movwf FSR0 - call Keypad_Read ; finds button pressed and stores in WREG - call Decode_Input_1 + call Keypad_Read ; finds button pressed and stores in WREG + call Decode_Input_1 ; Decodes digit movwf input_1 movlw 0xFF call delay_ms movlw 0xFF - cpfslt input_1 - bra User_Input_1 - decf digit_counter + cpfslt input_1 ; Checks for valid input + bra User_Input_1 ; repeat if valid button not pressed + decf digit_counter ; decrements digit count by 1 - call Second_Line + call Second_Line ; Writes digit to second line of LCD movlw input_address_1 movwf FSR2 movlw 1 @@ -61,20 +63,20 @@ User_Input_1: return User_Input_2: - movlw input_address_2 + movlw input_address_2 ; address to store second digit movwf FSR0 - call Keypad_Read ; finds button pressed and stores in WREG - call Decode_Input_2 + call Keypad_Read ; finds button pressed and stores in WREG + call Decode_Input_2 ; Decodes digit movwf input_2 movlw 0xFF call delay_ms movlw 0xFF - cpfslt input_2 - bra User_Input_2 - decf digit_counter + cpfslt input_2 ; Checks for valid input + bra User_Input_2 ; repeat if valid button not pressed + decf digit_counter ; decrements digit counter by 1 movlw input_address_2 movwf FSR2 @@ -86,7 +88,7 @@ User_Input_2: Decode_Input_1: movwf d1, A Error_Check_1: - movlw 0xFF ;ascii code for null + movlw 0xFF cpfseq d1, A bra Decode_0_1 retlw 0xFF @@ -95,7 +97,7 @@ Decode_0_1: movlw 0x7D cpfseq d1, A bra Decode_1_1 - movlw '0' + movlw '0' movwf INDF0 incf FSR0 retlw 0 @@ -107,7 +109,7 @@ Decode_1_1: movlw '1' movwf INDF0 incf FSR0 - retlw 10 + retlw 10 ; stores first digit as tens Decode_2_1: movlw 0xED @@ -185,7 +187,7 @@ Decode_9_1: Decode_Input_2: movwf d2, A Error_Check_2: - movlw 0xFF ;ascii code for null + movlw 0xFF cpfseq d2, A bra Decode_0_2 retlw 0xFF @@ -206,7 +208,7 @@ Decode_1_2: movlw '1' movwf INDF0 incf FSR0 - retlw 1 + retlw 1 ; stores second digit as units Decode_2_2: movlw 0xED From fdaf9f1f1b24edf4aacd3d7fcc26d2d471975cf3 Mon Sep 17 00:00:00 2001 From: amg121 Date: Fri, 15 Mar 2024 11:41:43 +0000 Subject: [PATCH 36/44] Added function to shift cursor to left --- LCD.s | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/LCD.s b/LCD.s index a731f84e..b6194e84 100644 --- a/LCD.s +++ b/LCD.s @@ -1,6 +1,6 @@ #include -global LCD_Setup, LCD_Write_Message, LCD_Clear, Second_Line +global LCD_Setup, LCD_Write_Message, LCD_Clear, Second_Line, Shift_Left, LCD_Send_Byte_D psect udata_acs ; named variables in access ram LCD_cnt_l: ds 1 ; reserve 1 byte for variable LCD_cnt_l @@ -117,6 +117,13 @@ Second_Line: movwf 10 call LCD_delay_ms return + +Shift_Left: + movlw 0x10 + call LCD_Send_Byte_I + movwf 10 + call LCD_delay_ms + return ; ** a few delay routines below here as LCD timing can be quite critical **** LCD_delay_ms: ; delay given in ms in W From b1c1d09a8591dfcf08bdb5b4c6fb27a9ca75e0a8 Mon Sep 17 00:00:00 2001 From: amg121 Date: Fri, 15 Mar 2024 11:42:02 +0000 Subject: [PATCH 37/44] Cleaned up --- main.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.s b/main.s index 8a6a9513..be28d901 100644 --- a/main.s +++ b/main.s @@ -47,7 +47,7 @@ start: call delay_ms call User_Input_Setup ; Waits for user input - ; (8-bit/2-digits) + ; (8-bit/2-digits goto $ From 27c621318937ecd91b9a3e6a2815fdead34b80b4 Mon Sep 17 00:00:00 2001 From: amg121 Date: Fri, 15 Mar 2024 11:42:23 +0000 Subject: [PATCH 38/44] Added backspace (in progress) --- Digit_Input.s | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/Digit_Input.s b/Digit_Input.s index 9299b7d2..c08225b6 100644 --- a/Digit_Input.s +++ b/Digit_Input.s @@ -1,8 +1,9 @@ #include global User_Input_Setup -extrn Keypad_Setup, Keypad_Read -extrn LCD_Setup, LCD_Write_Message, LCD_Clear, Second_Line +extrn Keypad_Read +extrn LCD_Write_Message, LCD_Clear, Second_Line, Shift_Left +extrn LCD_Send_Byte_D extrn input_address_1, input_address_2, delay_ms psect udata_acs ; reserve data space in access ram @@ -13,24 +14,30 @@ input_1: ds 1 input_2: ds 1 before_dec: ds 1 + psect udata_bank4 ; reserve data anywhere in RAM myArray: ds 0x80 psect input_code, class=CODE User_Input_Setup: - movlw 2 - movwf digit_counter ; setting the number of digits to be - ; inputted as 2 - + Input_1: call User_Input_1 + + Input_2: call User_Input_2 + call delay_ms movff input_1, WREG ; adding together the two digits to ; create one 8 bit number addwf input_2, W movwf before_dec + movlw before_dec + movwf FSR2 + movlw 1 + call LCD_Clear + call LCD_Write_Message call delay_ms call delay_ms @@ -52,7 +59,6 @@ User_Input_1: movlw 0xFF cpfslt input_1 ; Checks for valid input bra User_Input_1 ; repeat if valid button not pressed - decf digit_counter ; decrements digit count by 1 call Second_Line ; Writes digit to second line of LCD movlw input_address_1 @@ -76,12 +82,12 @@ User_Input_2: movlw 0xFF cpfslt input_2 ; Checks for valid input bra User_Input_2 ; repeat if valid button not pressed - decf digit_counter ; decrements digit counter by 1 movlw input_address_2 movwf FSR2 movlw 1 call LCD_Write_Message + clrf FSR2 return @@ -182,8 +188,7 @@ Decode_9_1: movwf INDF0 incf FSR0 retlw 90 - - + Decode_Input_2: movwf d2, A Error_Check_2: @@ -267,12 +272,24 @@ Decode_7_2: Decode_8_2: movlw 0xBD cpfseq d2, A - bra Decode_9_2 + bra Decode_B_2 movlw '8' movwf INDF0 incf FSR0 retlw 8 - + +Decode_B_2: + movlw 0x7B + cpfseq d2, A + bra Decode_9_2 + call Shift_Left ; backspace = shift cursor left and + ; print a space + movlw ' ' + movwf FSR2 + movlw 1 + call LCD_Write_Message + bra Input_1 + Decode_9_2: movlw 0xBB cpfseq d2, A @@ -281,6 +298,5 @@ Decode_9_2: movwf INDF0 incf FSR0 retlw 9 - \ No newline at end of file From 4e13da91801f9f40ee1dfa8e7c58d0b15973412b Mon Sep 17 00:00:00 2001 From: amg121 Date: Fri, 15 Mar 2024 12:13:28 +0000 Subject: [PATCH 39/44] Added backspace (in progress) --- Digit_Input.s | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/Digit_Input.s b/Digit_Input.s index c08225b6..b5637b9f 100644 --- a/Digit_Input.s +++ b/Digit_Input.s @@ -27,22 +27,16 @@ User_Input_Setup: Input_2: call User_Input_2 - call delay_ms - +Add_Input: movff input_1, WREG ; adding together the two digits to ; create one 8 bit number addwf input_2, W movwf before_dec - movlw before_dec - movwf FSR2 - movlw 1 - call LCD_Clear - call LCD_Write_Message - + call delay_ms call delay_ms call delay_ms - + return User_Input_1: @@ -87,7 +81,6 @@ User_Input_2: movwf FSR2 movlw 1 call LCD_Write_Message - clrf FSR2 return From 28287598258166a718ad74a0ee8731d81e8a22dc Mon Sep 17 00:00:00 2001 From: amg121 Date: Tue, 19 Mar 2024 11:07:15 +0000 Subject: [PATCH 40/44] Added routine to return cursor to first line of LCD --- LCD.s | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/LCD.s b/LCD.s index b6194e84..c5a2e660 100644 --- a/LCD.s +++ b/LCD.s @@ -1,6 +1,7 @@ #include -global LCD_Setup, LCD_Write_Message, LCD_Clear, Second_Line, Shift_Left, LCD_Send_Byte_D +global LCD_Setup, LCD_Write_Message, LCD_Clear, Second_Line +global Shift_Left, First_Line psect udata_acs ; named variables in access ram LCD_cnt_l: ds 1 ; reserve 1 byte for variable LCD_cnt_l @@ -48,6 +49,7 @@ LCD_Setup: LCD_Write_Message: ; Message stored at FSR2, length stored in W movwf LCD_counter, A + LCD_Loop_message: movf POSTINC2, W, A call LCD_Send_Byte_D @@ -112,13 +114,20 @@ LCD_Clear: return Second_Line: - movlw 0011000000B ; Points to bottom row of LCD screen + movlw 0011000000B ; Points cursor to bottom row of LCD screen call LCD_Send_Byte_I movwf 10 call LCD_delay_ms return -Shift_Left: +First_Line: ; Points cursor to the top row of LCD + movlw 00110000B + call LCD_Send_Byte_I + movwf 10 + call LCD_delay_ms + return + +Shift_Left: ; Moves cursor one space to the left movlw 0x10 call LCD_Send_Byte_I movwf 10 From d447d9799817116ee3f68e66dd590867c7a11f4f Mon Sep 17 00:00:00 2001 From: amg121 Date: Tue, 19 Mar 2024 11:07:42 +0000 Subject: [PATCH 41/44] Added output routine --- main.s | 71 +++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 55 insertions(+), 16 deletions(-) diff --git a/main.s b/main.s index be28d901..9baa214a 100644 --- a/main.s +++ b/main.s @@ -1,12 +1,14 @@ #include -global inputangle, delay_ms, input_address_1, input_address_2 +global inputangle, delay_ms, input_address_1, input_address_2, sine, cosine +global start extrn UART_Setup, UART_Transmit_Message ; external subroutines -extrn LCD_Setup, LCD_Write_Message, LCD_Clear, Second_Line +extrn LCD_Setup, LCD_Write_Message, LCD_Clear, Second_Line, First_Line extrn Keypad_Setup, Keypad_Read -extrn Input_Angle -extrn User_Input_Setup +extrn Input_Angle, Sine_Msg, Cosine_Msg +extrn User_Input_Setup, Press_Clear +;extrn cordic_setup psect udata_acs ; reserve data space in access ram counter: ds 1 @@ -17,6 +19,8 @@ cnt_h: ds 1 ; reserve 1 byte for variable cnt_h input_address_1 EQU 0xB0 input_address_2 EQU 0xC0 inputangle EQU 0xA0 + sine EQU 0xD0 + cosine EQU 0xE0 psect udata_bank4 ; reserve data anywhere in RAM myArray: ds 0x80 @@ -30,25 +34,60 @@ setup: bcf CFGS ; point to Flash program memory bsf EEPGD ; access Flash program memory call UART_Setup ; setup UART call LCD_Setup ; setup LCD - call Keypad_Setup + call Keypad_Setup ; setup Keypad + ;call cordic_setup ; setup CORDIC - call Input_Angle ; load message + call Input_Angle ; load all messages + call Sine_Msg + call Cosine_Msg goto start ; ******* Main programme **************************************** start: - movlw inputangle ; Writes 'input angle' messge - movwf FSR2 - movlw 12 - call LCD_Write_Message - call delay_ms - call delay_ms - call delay_ms - - call User_Input_Setup ; Waits for user input + movlw inputangle ; Writes 'input angle' message + movwf FSR2 + movlw 12 ; Number of characters in message + call LCD_Write_Message + + call delay_ms + call delay_ms + call delay_ms + + call Second_Line ; Move cursor to second line + + call User_Input_Setup ; Waits for user input ; (8-bit/2-digits - goto $ + call delay_ms + goto output + +output: + call First_Line + movlw sine ; Writing sine msg + value to + ; first line of LCD + movwf FSR2 + movlw 5 ; Number of characters in message + call LCD_Write_Message + + call delay_ms + call delay_ms + call delay_ms + + call Second_Line ; Writing Cosine msg + value to + ; second line of LCD + movlw cosine + movwf FSR2 + movlw 7 ; Number of characters in message + call LCD_Write_Message + + call delay_ms + call delay_ms + call delay_ms + + call Press_Clear ; Checks foor C button press + call First_Line ; Moves cursor back to start position + goto start ; Restarts programme + ;Delay Routines From cc93c56f46d4f39a6857e4c3f0ae392c76751fc2 Mon Sep 17 00:00:00 2001 From: amg121 Date: Tue, 19 Mar 2024 11:08:02 +0000 Subject: [PATCH 42/44] Fixed backspace and added clear and enter buttons --- Digit_Input.s | 571 ++++++++++++++++++++++++++++---------------------- 1 file changed, 322 insertions(+), 249 deletions(-) diff --git a/Digit_Input.s b/Digit_Input.s index b5637b9f..aaab6306 100644 --- a/Digit_Input.s +++ b/Digit_Input.s @@ -1,10 +1,10 @@ #include -global User_Input_Setup +global User_Input_Setup, Press_Clear extrn Keypad_Read extrn LCD_Write_Message, LCD_Clear, Second_Line, Shift_Left -extrn LCD_Send_Byte_D -extrn input_address_1, input_address_2, delay_ms +extrn input_address_1, input_address_2, delay_ms, start +;extrn cordic_loop psect udata_acs ; reserve data space in access ram digit_counter: ds 1 @@ -13,6 +13,8 @@ d2: ds 1 input_1: ds 1 input_2: ds 1 before_dec: ds 1 +enter: ds 1 +clear: ds 1 psect udata_bank4 ; reserve data anywhere in RAM @@ -22,274 +24,345 @@ psect input_code, class=CODE User_Input_Setup: Input_1: - call User_Input_1 + call User_Input_1 ; Input first digit Input_2: - call User_Input_2 + call User_Input_2 ; Input second digit Add_Input: - movff input_1, WREG ; adding together the two digits to + movff input_1, WREG ; adding together the two digits to ; create one 8 bit number - addwf input_2, W - movwf before_dec + addwf input_2, W + movwf before_dec - call delay_ms - call delay_ms - call delay_ms + call delay_ms + call delay_ms + call delay_ms - return +Press_Enter: ; Checks to see if E button pressed + call Keypad_Read + call Decode_Enter + movwf enter + + movlw 0xFF + call delay_ms + + movlw 0xFF + cpfslt enter + bra Press_Enter + + call LCD_Clear ; Clear screen + ;call cordic_loop ; Calculate cosine and sine values + +return -User_Input_1: - movlw input_address_1 ; address to store first digit - movwf FSR0 +Press_Clear: ; Checks to see if C button pressed + call Keypad_Read + call Decode_Clear + movwf clear - call Keypad_Read ; finds button pressed and stores in WREG - call Decode_Input_1 ; Decodes digit - movwf input_1 - - movlw 0xFF - call delay_ms - - movlw 0xFF - cpfslt input_1 ; Checks for valid input - bra User_Input_1 ; repeat if valid button not pressed - - call Second_Line ; Writes digit to second line of LCD - movlw input_address_1 - movwf FSR2 - movlw 1 - call LCD_Write_Message - - return - -User_Input_2: - movlw input_address_2 ; address to store second digit - movwf FSR0 + movlw 0xFF + call delay_ms - call Keypad_Read ; finds button pressed and stores in WREG - call Decode_Input_2 ; Decodes digit - movwf input_2 - - movlw 0xFF - call delay_ms + movlw 0xFF + cpfslt clear + bra Press_Clear + + call LCD_Clear ; Clear Screen + + return - movlw 0xFF - cpfslt input_2 ; Checks for valid input - bra User_Input_2 ; repeat if valid button not pressed +User_Input_1: + movlw input_address_1 ; address to store first digit + movwf FSR0 + + call Keypad_Read ; finds button pressed and stores in WREG + call Decode_Input_1 ; Decodes digit + movwf input_1 + + movlw 0xFF + call delay_ms + + movlw 0xFF + cpfslt input_1 ; Checks for valid input + bra User_Input_1 ; repeat if valid button not pressed + + movlw input_address_1 + movwf FSR2 + movlw 1 + call LCD_Write_Message + + return - movlw input_address_2 - movwf FSR2 - movlw 1 - call LCD_Write_Message +User_Input_2: + movlw input_address_2 ; address to store second digit + movwf FSR0 + + call Keypad_Read ; finds button pressed and stores in WREG + call Decode_Input_2 ; Decodes digit + movwf input_2 + + movlw 0xFF + call delay_ms + + movlw 0x7B + cpfseq input_2 + bra No_Backspace + goto Backspace + + No_Backspace: + movlw 0xFF + cpfslt input_2 ; Checks for valid input + bra User_Input_2 ; repeat if valid button not pressed + + movlw input_address_2 + movwf FSR2 + movlw 1 + call LCD_Write_Message + + return - return +Backspace: + call Shift_Left ; backspace = shift cursor left and + ; print a space + movlw 'N' + + movwf FSR2 + movlw 1 + call LCD_Write_Message + goto Input_1 Decode_Input_1: movwf d1, A -Error_Check_1: - movlw 0xFF - cpfseq d1, A - bra Decode_0_1 - retlw 0xFF - -Decode_0_1: - movlw 0x7D - cpfseq d1, A - bra Decode_1_1 - movlw '0' - movwf INDF0 - incf FSR0 - retlw 0 - -Decode_1_1: - movlw 0xEE - cpfseq d1, A - bra Decode_2_1 - movlw '1' - movwf INDF0 - incf FSR0 - retlw 10 ; stores first digit as tens - -Decode_2_1: - movlw 0xED - cpfseq d1, A - bra Decode_3_1 - movlw '2' - movwf INDF0 - incf FSR0 - retlw 20 -Decode_3_1: - movlw 0xEB - cpfseq d1, A - bra Decode_4_1 - movlw '3' - movwf INDF0 - incf FSR0 - retlw 30 - -Decode_4_1: - movlw 0xDE - cpfseq d1, A - bra Decode_5_1 - movlw '4' - movwf INDF0 - incf FSR0 - retlw 40 - -Decode_5_1: - movlw 0xDD - cpfseq d1, A - bra Decode_6_1 - movlw '5' - movwf INDF0 - incf FSR0 - retlw 50 - -Decode_6_1: - movlw 0xDB - cpfseq d1, A - bra Decode_7_1 - movlw '6' - movwf INDF0 - incf FSR0 - retlw 60 - -Decode_7_1: - movlw 0xBE - cpfseq d1, A - bra Decode_8_1 - movlw '7' - movwf INDF0 - incf FSR0 - retlw 70 - -Decode_8_1: - movlw 0xBD - cpfseq d1, A - bra Decode_9_1 - movlw '8' - movwf INDF0 - incf FSR0 - retlw 80 - -Decode_9_1: - movlw 0xBB - cpfseq d1, A - retlw 0xFF - movlw '9' - movwf INDF0 - incf FSR0 - retlw 90 + Error_Check_1: + movlw 0xFF + cpfseq d1, A + bra Decode_0_1 + retlw 0xFF + + Decode_0_1: + movlw 0x7D + cpfseq d1, A + bra Decode_1_1 + movlw '0' + movwf INDF0 + incf FSR0 + retlw 0 + + Decode_1_1: + movlw 0xEE + cpfseq d1, A + bra Decode_2_1 + movlw '1' + movwf INDF0 + incf FSR0 + retlw 10 ; stores first digit as tens + + Decode_2_1: + movlw 0xED + cpfseq d1, A + bra Decode_3_1 + movlw '2' + movwf INDF0 + incf FSR0 + retlw 20 + + Decode_3_1: + movlw 0xEB + cpfseq d1, A + bra Decode_4_1 + movlw '3' + movwf INDF0 + incf FSR0 + retlw 30 + + Decode_4_1: + movlw 0xDE + cpfseq d1, A + bra Decode_5_1 + movlw '4' + movwf INDF0 + incf FSR0 + retlw 40 + + Decode_5_1: + movlw 0xDD + cpfseq d1, A + bra Decode_6_1 + movlw '5' + movwf INDF0 + incf FSR0 + retlw 50 + + Decode_6_1: + movlw 0xDB + cpfseq d1, A + bra Decode_7_1 + movlw '6' + movwf INDF0 + incf FSR0 + retlw 60 + + Decode_7_1: + movlw 0xBE + cpfseq d1, A + bra Decode_8_1 + movlw '7' + movwf INDF0 + incf FSR0 + retlw 70 + + Decode_8_1: + movlw 0xBD + cpfseq d1, A + bra Decode_9_1 + movlw '8' + movwf INDF0 + incf FSR0 + retlw 80 + + Decode_9_1: + movlw 0xBB + cpfseq d1, A + retlw 0xFF + movlw '9' + movwf INDF0 + incf FSR0 + retlw 90 Decode_Input_2: movwf d2, A -Error_Check_2: - movlw 0xFF - cpfseq d2, A - bra Decode_0_2 - retlw 0xFF - -Decode_0_2: - movlw 0x7D - cpfseq d2, A - bra Decode_1_2 - movlw '0' - movwf INDF0 - incf FSR0 - retlw 0 - -Decode_1_2: - movlw 0xEE - cpfseq d2, A - bra Decode_2_2 - movlw '1' - movwf INDF0 - incf FSR0 - retlw 1 ; stores second digit as units - -Decode_2_2: - movlw 0xED - cpfseq d2, A - bra Decode_3_2 - movlw '2' - movwf INDF0 - incf FSR0 - retlw 2 - -Decode_3_2: - movlw 0xEB - cpfseq d2, A - bra Decode_4_2 - movlw '3' - movwf INDF0 - incf FSR0 - retlw 3 - -Decode_4_2: - movlw 0xDE - cpfseq d2, A - bra Decode_5_2 - movlw '4' - movwf INDF0 - incf FSR0 - retlw 4 -Decode_5_2: - movlw 0xDD - cpfseq d2, A - bra Decode_6_2 - movlw '5' - movwf INDF0 - incf FSR0 - retlw 5 - -Decode_6_2: - movlw 0xDB - cpfseq d2, A - bra Decode_7_2 - movlw '6' - movwf INDF0 - incf FSR0 - retlw 6 + Error_Check_2: + movlw 0xFF + cpfseq d2, A + bra Decode_0_2 + retlw 0xFF + + Decode_0_2: + movlw 0x7D + cpfseq d2, A + bra Decode_1_2 + movlw '0' + movwf INDF0 + incf FSR0 + retlw 0 + + Decode_1_2: + movlw 0xEE + cpfseq d2, A + bra Decode_2_2 + movlw '1' + movwf INDF0 + incf FSR0 + retlw 1 ; stores second digit as units + + Decode_2_2: + movlw 0xED + cpfseq d2, A + bra Decode_3_2 + movlw '2' + movwf INDF0 + incf FSR0 + retlw 2 + + Decode_3_2: + movlw 0xEB + cpfseq d2, A + bra Decode_4_2 + movlw '3' + movwf INDF0 + incf FSR0 + retlw 3 + + Decode_4_2: + movlw 0xDE + cpfseq d2, A + bra Decode_5_2 + movlw '4' + movwf INDF0 + incf FSR0 + retlw 4 + + Decode_5_2: + movlw 0xDD + cpfseq d2, A + bra Decode_6_2 + movlw '5' + movwf INDF0 + incf FSR0 + retlw 5 + + Decode_6_2: + movlw 0xDB + cpfseq d2, A + bra Decode_7_2 + movlw '6' + movwf INDF0 + incf FSR0 + retlw 6 + + Decode_7_2: + movlw 0xBE + cpfseq d2, A + bra Decode_8_2 + movlw '7' + movwf INDF0 + incf FSR0 + retlw 7 + + Decode_8_2: + movlw 0xBD + cpfseq d2, A + bra Decode_B_2 + movlw '8' + movwf INDF0 + incf FSR0 + retlw 8 + + Decode_B_2: + movlw 0x7B + cpfseq d2, A + bra Decode_9_2 + retlw 0x7B + + Decode_9_2: + movlw 0xBB + cpfseq d2, A + retlw 0xFF + movlw '9' + movwf INDF0 + incf FSR0 + retlw 9 -Decode_7_2: - movlw 0xBE - cpfseq d2, A - bra Decode_8_2 - movlw '7' - movwf INDF0 - incf FSR0 - retlw 7 -Decode_8_2: - movlw 0xBD - cpfseq d2, A - bra Decode_B_2 - movlw '8' - movwf INDF0 - incf FSR0 - retlw 8 +Decode_Enter: + movwf enter, A -Decode_B_2: - movlw 0x7B - cpfseq d2, A - bra Decode_9_2 - call Shift_Left ; backspace = shift cursor left and - ; print a space - movlw ' ' - movwf FSR2 - movlw 1 - call LCD_Write_Message - bra Input_1 + Error_Check_E: + movlw 0xFF + cpfseq enter, A + bra Decode_E + retlw 0xFF + + Decode_E: + movlw 0xD7 + cpfseq enter, A + retlw 0xFF + return + +Decode_Clear: + movwf clear, A -Decode_9_2: - movlw 0xBB - cpfseq d2, A - retlw 0xFF - movlw '9' - movwf INDF0 - incf FSR0 - retlw 9 - - \ No newline at end of file + Error_Check_C: + movlw 0xFF + cpfseq clear, A + bra Decode_C + retlw 0xFF + + Decode_C: + movlw 0x77 + cpfseq clear, A + retlw 0xFF + return \ No newline at end of file From 4ee944a0df5f80ef689aa97928ffcc4378097184 Mon Sep 17 00:00:00 2001 From: amg121 Date: Tue, 19 Mar 2024 11:08:17 +0000 Subject: [PATCH 43/44] Added sine and cosine messages --- Messages.s | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/Messages.s b/Messages.s index 9d28c5f3..313e213a 100644 --- a/Messages.s +++ b/Messages.s @@ -1,7 +1,7 @@ #include -global Input_Angle -extrn inputangle +global Input_Angle, Sine_Msg, Cosine_Msg +extrn inputangle, sine, cosine psect Messages, class = CODE @@ -57,4 +57,62 @@ Input_Angle: movwf INDF0 return + +Cosine_Msg: + movlw cosine + movwf FSR0 + + movlw 'C' + movwf INDF0 + incf FSR0, F + + movlw 'o' + movwf INDF0 + incf FSR0, F + + movlw 's' + movwf INDF0 + incf FSR0, F + + movlw 'i' + movwf INDF0 + incf FSR0, F + + movlw 'n' + movwf INDF0 + incf FSR0, F + + movlw 'e' + movwf INDF0 + incf FSR0, F + + movlw ':' + movwf INDF0 + + return + +Sine_Msg: + movlw sine + movwf FSR0 + + movlw 'S' + movwf INDF0 + incf FSR0, F + + movlw 'i' + movwf INDF0 + incf FSR0, F + + movlw 'n' + movwf INDF0 + incf FSR0, F + + movlw 'e' + movwf INDF0 + incf FSR0, F + + movlw ':' + movwf INDF0 + + return From c20b4322256efd13588159a03353d875b5c9c437 Mon Sep 17 00:00:00 2001 From: amg121 Date: Tue, 19 Mar 2024 11:11:26 +0000 Subject: [PATCH 44/44] Reformatted --- Messages.s | 102 ++++++++++++++++++++++++++--------------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/Messages.s b/Messages.s index 313e213a..0eca9cac 100644 --- a/Messages.s +++ b/Messages.s @@ -6,57 +6,57 @@ extrn inputangle, sine, cosine psect Messages, class = CODE Input_Angle: - movlw inputangle - movwf FSR0 ; points to start of message - - movlw 'I' - movwf INDF0 - incf FSR0, F - - movlw 'n' - movwf INDF0 - incf FSR0, F - - movlw 'p' - movwf INDF0 - incf FSR0, F - - movlw 'u' - movwf INDF0 - incf FSR0, F - - movlw 't' - movwf INDF0 - incf FSR0, F - - movlw ' ' - movwf INDF0 - incf FSR0, F - - movlw 'A' - movwf INDF0 - incf FSR0, F - - movlw 'n' - movwf INDF0 - incf FSR0, F - - movlw 'g' - movwf INDF0 - incf FSR0, F - - movlw 'l' - movwf INDF0 - incf FSR0, F - - movlw 'e' - movwf INDF0 - incf FSR0, F - - movlw ':' - movwf INDF0 - - return + movlw inputangle + movwf FSR0 ; points to start of message + + movlw 'I' + movwf INDF0 + incf FSR0, F + + movlw 'n' + movwf INDF0 + incf FSR0, F + + movlw 'p' + movwf INDF0 + incf FSR0, F + + movlw 'u' + movwf INDF0 + incf FSR0, F + + movlw 't' + movwf INDF0 + incf FSR0, F + + movlw ' ' + movwf INDF0 + incf FSR0, F + + movlw 'A' + movwf INDF0 + incf FSR0, F + + movlw 'n' + movwf INDF0 + incf FSR0, F + + movlw 'g' + movwf INDF0 + incf FSR0, F + + movlw 'l' + movwf INDF0 + incf FSR0, F + + movlw 'e' + movwf INDF0 + incf FSR0, F + + movlw ':' + movwf INDF0 + + return Cosine_Msg: movlw cosine