8位单片机::pic汇编::实例学习::无死角学习0::串口与lcd显示

本文以一个8位单片机Pic为例,通过protues实例,深入学习汇编语言在串口通信和LCD显示的应用。文中详细解释了BSF指令配置RCSTA寄存器和TXSTA发送接收寄存器的过程,旨在帮助读者无死角理解汇编执行流程。
摘要由CSDN通过智能技术生成

        由于我本人刚刚接触pic汇编,但是目前工作时间不太多,也由于pic汇编指令较少,工作中习惯于c语言,所以汇编学习的目的是为了能读懂他人的汇编程序。此次采用实例学习,通过protues提供的例子实例图,汇编代码,无死角理解汇编执行过程。

                

            

汇编完整代码:

; Simple PIC 16F877X Program to drive Serial LCDs.
; Assumes 1MHZ CPU clock, 2400 baud rate for the LCD.

           LIST    p=16F874
           #include "P16F874.INC"

	   ; Counter variables for delay
           cblock 0x20
               char,cmd,lc1,lc2;
           endc

           ; Vector for normal start up.
           org     0
           goto    start

           org     4
           goto    inthlr

; Main program starts here:
start      clrw                    ; Clear W.
           movwf   PORTA           ; Ensure PORTA is zero before we enable it.
           movwf   PORTB           ; Ensure PORTB is zero before we enable it.

           ; Set up ports:
           bcf     STATUS,RP0      ; Select Bank 0
           bsf     RCSTA,SPEN      ; Enable USART.
           bsf	   RCSTA,CREN	   ; Enable Receeive
           bsf     STATUS,RP0      ; Select Bank 1
           clrw                    ; Set W to mask for all outputs.
           movwf   TRISA           ; Set TRISA register as outputs.
           movwf   TRISB           ; Set TRISB register as outputs.
           movlw   0x19            ; BRG value for 2400 baud @ 1MHz
           movwf   SPBRG           ; Write it to register.
           movlw   0xA4            ; CSRC/TXEN (Internal clock, 8 bit mode, Async operation, High Speed)
           movwf   TXSTA           ; Write to TX control register.           

	   movlw   80
	   call    delay

           movlw   'M'             ; Value to transmit.
	   call    putc                       
           movlw   'i'             ; Value to transmit.
	   call    putc                       
           movlw   'l'             ; Value to transmit.
	   call    putc                       
           movlw   'f'             ; Value to transmit.
	   call    putc                       
	   movlw  'o'              ; Value to transmit.
	   call    putc                       
           movlw  'r'              ; Value to transmit.
	   call    putc                       
	   movlw  'd'              ; Value to transmit.
	   call    putc                       
	   movlw  ' '              ; Value to transmit.
	   call    putc                       
	   movlw  'L'              ; Value to transmit.
	   call    putc                       
	   movlw  'C'              ; Value to transmit.
	   call    putc                       
	   movlw  'D'              ; Value to transmit.
	   call    putc                       
	   movlw  ' '              ; Value to transmit.
	   call    putc                       
	   movlw  'D'              ; Value to transmit.
	   call    putc                       
	   movlw  'e'              ; Value to transmit.
	   call    putc                       
	   movlw  'm'              ; Value to transmit.
	   call    putc                       
	   movlw  'o'              ; Value to transmit.
	   call    putc                       

	   movlw  0xC0 	           ; Move cursor to row two
	   call   wrcmd

	   movlw  0x0D 		   ; Show the cursor
	   call   wrcmd
	            
loop	   call  getc                                  
           movwf char           
	   sublw 0d
	   btfsc STATUS,Z
	   goto  cls	     
	   movf  char,w
	   sublw 08
	   btfsc STATUS,Z
	   goto  bspace
	   movf  char,W
	   call  putc    	  ; Send the character straight thru
	   goto  loop

cls        movlw  0x01		  ; Send command prefix
           call wrcmd
	   goto loop            

bspace     movlw 0x10		  ; Send command prefix
  	   call wrcmd
	   goto loop
	         
hang	   clrwdt                 ; Clear WDT in case it is enabled.
	   goto hang			

;Subroutine to sent a command
wrcmd	   movwf cmd    	  ; Store the command      
	   movlw 0xFE             ; Write the command prefix
	   call putc
	   movf cmd,W	          ; Write the command code
	   goto putc
	   
;Subroutine to wait and receive a byte
;Returns character in W
;
getc       bcf     STATUS,RP0      ; Select Bank 0.
getc1      btfss   PIR1,RCIF	   ; Skip if RC int flag set  
	   goto    getc1           ; Try again
	   movf	   RCREG,W         ; Read the character
	   bcf     PIR1,RCIF       ; Clear the interrupt flag
	   return

;Subroutine to transmit a byte and wait
;W = Character
;
putc       bcf     STATUS,RP0      ; Select Bank 0.
           movwf   TXREG           ; Write it!
           b
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值