vilfred
Member level 1
![Member level 1](/styles/images/ranks/dlevel1.gif)
Hi,
I'm not a good programmer, and iam new to pic world. I'm working in PIC18F65K22 to control a DC motor and stepper motor using UART at 9600bps. I've posted my code below. I need to receive and transmit a same character in UART to drive a specific function. But while simulating my code in proteus, i send a particular character and received an error value. Please correct me if iam doing any mistake in my code. Thanks
I'm not a good programmer, and iam new to pic world. I'm working in PIC18F65K22 to control a DC motor and stepper motor using UART at 9600bps. I've posted my code below. I need to receive and transmit a same character in UART to drive a specific function. But while simulating my code in proteus, i send a particular character and received an error value. Please correct me if iam doing any mistake in my code. Thanks
Code ASM - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 LIST P=18F65K22 INCLUDE <P18F65K22.INC> COUNTA EQU 01H COUNTB EQU 02H COUNTC EQU 03H CBLOCK 0x20 ENDC CONFIG WDTEN = OFF CONFIG MCLRE = OFF CONFIG XINST = OFF CONFIG DEBUG = OFF CONFIG FOSC = INTIO2 CONFIG BOREN = ON CONFIG IESO = ON ORG 0x00 MOVWF 0x00 MOVWF ANSEL1 MOVLW 0x66 MOVWF OSCCON GOTO UART_INIT UART_INIT MOVLW D'12' MOVWF SPBRG1 MOVLW B'00110000' MOVWF PIE1 MOVLW B'00110000' MOVWF PIR1 MOVLW B'01100110' MOVWF TXSTA1 MOVLW B'11010000' MOVWF RCSTA1 BCF TRISC,6 BSF TRISC,7 MAIN BTFSS PIR1,RCIF GOTO MAIN MOVWF RCREG1 BCF RCSTA1,CREN BSF RCSTA1,CREN BTFSC TXSTA1,TXIF GOTO MAIN MOVWF TXREG1 MOVLW 'A' CPFSLT RCREG1 GOTO MAIN MOVF RCREG1,W MOVWF TXREG1 GOTO DC1 MOVLW 'B' CPFSLT RCREG1 GOTO MAIN MOVF RCREG1,W MOVWF TXREG1 GOTO SM DC1 BCF TRISA,1 BSF PORTA,1 MOVLW 0x00 MOVWF TRISD BSF PORTD,0 CALL DELAY BCF PORTD,1 CALL DELAY BCF PORTA,1 CALL DELAY BCF PORTD,0 CALL DELAY BCF PORTA,1 GOTO MAIN SM MOVLW 0x00 MOVWF TRISB MOVLW B'00000001' MOVWF PORTB CALL DELAY MOVLW B'00000100' MOVWF PORTB CALL DELAY MOVLW B'00000010' MOVWF PORTB CALL DELAY MOVLW B'00001000' MOVWF PORTB GOTO MAIN DELAY MOVLW D'168' MOVWF COUNTA MOVLW D'24' MOVWF COUNTB MOVLW D'10' MOVWF COUNTC LOOP DECFSZ COUNTA,1 GOTO LOOP DECFSZ COUNTB,1 GOTO LOOP DECFSZ COUNTC,1 GOTO LOOP RETURN GOTO MAIN END
Last edited by a moderator: