PIC microcontroller serial port debugging program

Publisher:HeavenlyWhisperLatest update time:2017-12-04 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

;********************************************************************** 
;Use the serial port debugging wizard or the hyperterminal on the PC, set the baud rate to 9600, 8 data bits, 
;1 stop bit, no parity bit. 
;When burning, pay attention to the oscillation mode XT, and WDT should be disabled. 
;*********************************************************************** 

   LIST P=16F877 
   INCLUDE "P16F877.INC" 
;**************************************** 
;__CONFIG _DEBUG_OFF&_CP_ALL&_WRT_HALF&_CPD_ON&_LVP_OFF&_BODEN_OFF&_PWRTE_ON&_WDT_OFF&_HS_OSC; 
;************************ 
   CB LOC K 0x20 
TXBUFF :9 
TXPTR 
TXCOUNT 
RXBUFF :9 
PUTPTR 
GETPTR 
STATUS_TEMP 
FSR_TEMP 
   ENDC 
;******* *************************** 

W_TEMP EQU 7FH 
;********************** *************** 
   ORG 0X000 
   GOTO MAIN 
   ORG 0X004 
   GOTO INT 
   ORG 0X008 
;************************ ********** 
INT 
   MOVWF W_TEMP ; protect the scene 
   SWAPF STATUS,W 
   CLRF STATUS 
   MOVWF STATUS_TEMP 
   MOVFW FSR 
   MOVWF FSR_TEMP 
;------------------------ 
CHKRXINT 
   BANKSEL PIR1 
   BTFSS PIR1,RCIF ; Check if it is an interrupt request issued by USART 
   GOTO CHKTXINT 
;---------------------------- 
_RDRXFIFO 
   BTFSC RCSTA,FERR ;Frame format error flag 
   GOTO _FERR_PRO 

   MOVLW RXBUFF ; 
   MOVWF FSR 

   MOVF PUTPTR,W 
   ADDWF FSR,F 
   MOVF RCREG,W 
   MOVWF INDF 
   INCF PUTPTR,F 
; MOVLW .7 
; ANDWF PUTPTR,F 

   BTFSC PIR1,RCIF 
   GOTO _RDRXFIFO 
;--------- ----------------- 
   BTFSS RCSTA,OERR ;Overspeed error flag 
   GOTO ENDOFINT 
;------------------------ 
_OERR_PRO 
   BCF RCSTA,CREN ;0=Disable continuous receiving function 
   BSF RCSTA,CREN ;1 = Enable continuous receiving function 
   GOTO ENDOFINT 
;------------------------ 
_FERR_PRO 
   MOVF RCREG,W 
   GOTO ENDOFINT 
;********* *************************** 
;Send program 
CHKTXINT 
   BSF STATUS, RP0 ;Set file register body 1 
   BTFSS PIE1, TXIE ;Send interrupt flag Enable bit 
   GOTO ENDOFINT 
   BCF STATUS, RP0 ; Restore to file register 0 

   BTFSS PIR1, TXIF ; Transmit interrupt flag bit 
   GOTO ENDOFINT 
; ---------------------- - 
   MOVLW TXBUFF ; Send temporary register = 20H 
   MOVWF FSR 
   MOVF TXPTR,W 
   ADDWF FSR,F 
   MOVF INDF,W 
   MOVWF TXREG 
   INCF TXPTR,F 
   DECFSZ TXCOUNT,F ;Number of data bits to be sent 
   GOTO ENDOFINT 
;---------------------- 
   BSF STATUS,RP0 
   BCF PIE1,TXIE ;Send interrupt bit disable 
   BCF STATUS, RP0 
;-------------------------- 
ENDOFINT ;Restore the scene 
   CLRF STATUS 
   MOVFW FSR_TEMP 
   MOVWF FSR 
   SWAPF STATUS_TEMP,W 
   MOVWF STATUS 
   SWAPF W_TEMP,F 
   SWAPF W_TEMP,W 
   RETFIE 
;******************************************************** 

;**************************************************** 
MAIN 
   BANKSEL TXSTA ;Set file register bank 1 
   MOVLW B'00100100' ;Enable USART transmission, set baud rate generator to high speed mode 
   MOVWF TXSTA 

   MOVLW .25 ;Load baud rate generator to 9600 
   MOVWF SPBRG     

   CLRF PIE1 
   BSF PIE1,RCIE ;Open USART receive interrupt 
   CLRF STATUS ;Restore to file register bank 0 

   CLRF TXCOUNT 
   CLRF GETPTR 
   CLRF PUTPTR 

   MOVLW B'10010000' ; Enable USART continuous reception and enable USART port 
   MOVWF RCSTA 

   CLRF I NTC ON 
   BSF INTCON,PEIE ; ​​Enable peripheral interrupt enable bit 
   BSF INTCON,GIE ; Enable global interrupt enable bit 
; ************************************** 
LOOP 
   CALL CHECK_DATA 
   GOTO LOOP 
; ************************************** 
CHECK_DATA 
   CLRF STATUS 
   MOVF TXCOUNT,W 
   SKPZ ;BTFSS STATUS,Z 
   RETURN 
;-------------------------------- 
   MOVF GETPTR,W 
   XORWF PUTPTR,W  
   SKPNZ ;BTFSC STATUS,Z 
   RETURN  
;-------------------------------- 
   MOVLW RXBUFF 
   MOVWF FSR 
   MOVF GETPTR,W 
   ADDWF FSR,F 

   INCF GETPTR,F 
; MOVLW .7 
; ANDWF GETPTR,F 

   MOVF INDF,W 
   MOVWF TXBUFF+0 
;---------------------------------- 
; MOVLW '-' 
; MOVWF TXBUFF+1 
; MOVLW 'P' 
; MOVWF TXBUFF+2  ; MOVLW 
'I' 
; '  V'  ; MOVWF TXBUFF+6  ;  MOVLW  'R'  ; MOVWF TXBUFF  +7  ;---------------------------------     MOVLW 0X0D ; Enter key      MOVWF TXBUFF+1      MOVLW 0X0A ; Line feed key      MOVWF TXBUFF+2  ;-----------------------------     MOVLW .3     MOVWF TXCOUNT     CLRF TXPTR ; Clear 0     BSF STATUS, RP0     BSF PIE1, TXIE     BCF STATUS, RP0     RETURN  ;---------------------------     END 
























Reference address:PIC microcontroller serial port debugging program

Previous article:Ethernet-RS-232 Protocol Converter Based on PIC18F66J60
Next article:PIC16F72 Timer C Program

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号