diff --git a/Digit_Input.s b/Digit_Input.s new file mode 100644 index 00000000..aaab6306 --- /dev/null +++ b/Digit_Input.s @@ -0,0 +1,368 @@ +#include + +global User_Input_Setup, Press_Clear +extrn Keypad_Read +extrn LCD_Write_Message, LCD_Clear, Second_Line, Shift_Left +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 +d1: ds 1 +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 +myArray: ds 0x80 + +psect input_code, class=CODE + +User_Input_Setup: + Input_1: + call User_Input_1 ; Input first digit + + Input_2: + call User_Input_2 ; Input second digit + +Add_Input: + movff input_1, WREG ; adding together the two digits to + ; create one 8 bit number + addwf input_2, W + movwf before_dec + + call delay_ms + call delay_ms + call delay_ms + +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 + +Press_Clear: ; Checks to see if C button pressed + call Keypad_Read + call Decode_Clear + movwf clear + + movlw 0xFF + call delay_ms + + movlw 0xFF + cpfslt clear + bra Press_Clear + + call LCD_Clear ; Clear Screen + + return + +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 + +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 + +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 + +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 + + 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_Enter: + movwf enter, A + + 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 + + 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 diff --git a/Keypad.s b/Keypad.s new file mode 100644 index 00000000..96ea4193 --- /dev/null +++ b/Keypad.s @@ -0,0 +1,190 @@ +#include + +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 +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 + movlw 1 + call delay_ms + + return + +Keypad_Read: + ; reading column + movlw 0x00 + movwf PORTE, A + movff PORTE, col + movlw 1 + call delay_ms + + ; reading row + movlw 0xF0 + movwf TRISE, A + movlw 1 + call delay_ms + + movwf PORTE, A + movff PORTE, row + + + ;finding button + movff row, WREG + iorwf col, W, A + movwf button, A + movlw 0x0F + movwf TRISE, A + + movff button, WREG + ;call Error_Check + return + +Error_Check: + movlw 0xFF ;ascii code for null + cpfseq button, A + bra Decode_0 + retlw 0xFF + +Decode_0: + movlw 0x7D + cpfseq button, A + bra Decode_1 + retlw '0' + +Decode_1: + movlw 0xEE + cpfseq button, A + bra Decode_2 + retlw '1' + +Decode_2: + movlw 0xED + cpfseq button, A + bra Decode_3 + retlw '2' + +Decode_3: + movlw 0xEB + cpfseq button, A + bra Decode_4 + retlw '3' + +Decode_4: + movlw 0xDE + cpfseq button, A + bra Decode_5 + retlw '4' + +Decode_5: + movlw 0xDD + cpfseq button, A + bra Decode_6 + retlw '5' + +Decode_6: + movlw 0xDB + cpfseq button, A + bra Decode_7 + retlw '6' + +Decode_7: + movlw 0xBE + cpfseq button, A + bra Decode_8 + retlw '7' + +Decode_8: + movlw 0xBD + cpfseq button, A + bra Decode_9 + retlw '8' + +Decode_9: + movlw 0xBB + cpfseq button, A + bra Decode_A + retlw '9' + +Decode_A: + movlw 0x7E + cpfseq button, A + bra Decode_B + retlw 'A' + +Decode_B: + movlw 0x7B + cpfseq button, A + bra Decode_C + retlw 'B' + +Decode_C: + movlw 0x77 + cpfseq button, A + bra Decode_D + retlw 'C' + +Decode_D: + movlw 0xB7 + cpfseq button, A + bra Decode_E + retlw 'D' + +Decode_E: + movlw 0xD7 + cpfseq button, A + bra Decode_F + retlw 'E' + +Decode_F: + movlw 0xE7 + cpfseq button, A + retlw 0xFF + retlw 'F' + +;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 diff --git a/LCD.s b/LCD.s new file mode 100644 index 00000000..c5a2e660 --- /dev/null +++ b/LCD.s @@ -0,0 +1,167 @@ +#include + +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 +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 + + +LCD_Clear: + movlw 00000001B ; Clears LCD screen + call LCD_Send_Byte_I + return + +Second_Line: + movlw 0011000000B ; Points cursor to bottom row of LCD screen + call LCD_Send_Byte_I + movwf 10 + call LCD_delay_ms + return + +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 + 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 +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/Messages.s b/Messages.s new file mode 100644 index 00000000..0eca9cac --- /dev/null +++ b/Messages.s @@ -0,0 +1,118 @@ +#include + +global Input_Angle, Sine_Msg, Cosine_Msg +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 + +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 + diff --git a/README.md b/README.md index b175f5e5..57dd621a 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 + +Initialises UART and writes a message (the table) to UART diff --git a/Simple1.asm b/Simple1.asm deleted file mode 100755 index f7777b2e..00000000 --- a/Simple1.asm +++ /dev/null @@ -1,21 +0,0 @@ - #include p18f87k22.inc - - code - org 0x0 - goto start - - 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 - - end diff --git a/UART.s b/UART.s new file mode 100644 index 00000000..32bf8df9 --- /dev/null +++ b/UART.s @@ -0,0 +1,36 @@ +#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 uart_code,class=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 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 + 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 + + diff --git a/config.asm b/config.s similarity index 95% rename from config.asm rename to config.s index 5c06fac2..5fa7cad1 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..9baa214a --- /dev/null +++ b/main.s @@ -0,0 +1,121 @@ +#include + +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, First_Line +extrn Keypad_Setup, Keypad_Read +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 +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 + sine EQU 0xD0 + cosine EQU 0xE0 + +psect udata_bank4 ; reserve data anywhere in RAM +myArray: ds 0x80 + +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 + call UART_Setup ; setup UART + call LCD_Setup ; setup LCD + call Keypad_Setup ; setup Keypad + ;call cordic_setup ; setup CORDIC + + call Input_Angle ; load all messages + call Sine_Msg + call Cosine_Msg + + goto start + + ; ******* Main programme **************************************** +start: + 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 + 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 +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 + 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 diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index ad70b23a..dcbd0e3b 100755 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -1,5 +1,5 @@ - + - Simple1.asm - config.asm + config.s + main.s + UART.s + LCD.s + Keypad.s + Messages.s + Digit_Input.s PIC18F87K22 - Simulator - MPASMWIN - 5.77 - 4 + pk4hybrid + pic-as + 2.45 + 3 + + + + + @@ -51,6 +61,7 @@ false + false false @@ -58,27 +69,640 @@ 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 +