caramoan tour package

caramoan tour package

Author Topic: Assembly code for PIC16F877A UART Reception  (Read 623 times)

Offline clarkent

  • Lead Acid Battery
  • *******
  • Posts: 505
  • Pogi/Ganda Points: 20
  • Gender: Male
  • iehs
Assembly code for PIC16F877A UART Reception
« on: January 07, 2011, 10:56:39 AM »
Code: [Select]
#include<P16f877a.inc>
__CONFIG _WDT_OFF & _PWRTE_ON & _XT_OSC & _LVP_OFF

load   equ 0x20
buffer  equ 0x21

Start:   
bsf STATUS,RP0
clrf TRISD
        movlw 0x80     ;RC0-RC3 as output
        movwf TRISC
        movlw D'25'            ;baudrate = 9600
        movwf SPBRG
        movlw b'00100100'   ; brgh = 1
        movwf TXSTA         ; enable Async Transmission, set brgh
        bcf STATUS,RP0         
movlw b'10010000'   ; enable Async Reception
        movwf RCSTA
clrf PORTC

settle: 
decfsz load,1
        goto settle

    movf RCREG,W
    movf RCREG,W
    movf RCREG,W    ; flush receive buffer
   
Loop:
call Receive        ; wait for a char
movwf buffer
test_a:
movf buffer,W ;comprare the received data
xorlw 'a' ;with ascii 'a'
btfss STATUS,Z
goto test_s
goto leds1 ;if the received data is 'a', goto leds1
test_s:
movf buffer,W ;comprare the received data
xorlw 's' ;with ascii 's'
btfss STATUS,Z
goto Loop
goto leds2 ;if the received data is 'a', goto leds2

leds1:
movlw 01h ;an 'a' will turn-on LED at RC0
movwf PORTC
goto Loop
leds2:
movlw 02h ;an 's' will turn-on LED at RC1
movwf PORTC
goto Loop

Receive:
clrf RCREG
btfss PIR1,RCIF     ;check for received data
    goto Receive
    movf RCREG,W ; copy the received data from RCREG to W
    return

        end

mga sirs,

ano po kaya ang problema o kulang dyan sa code kung bakit di sya gumagana sa actual hardware. sa proteus kasi it works fine. i checked the hardware that i'm using, i tried a code that will enable the pic16f877a to send the word "WARNING!" to my PC and it worked. pero pag ang code na sa taas ang ginagamit ko hindi na gumagana sa hardware, sa proteus lang sya gumagana ng maayos.
if you think you can or think you can't, you're probably right -h.ford

Philippine Electronics Forum

Assembly code for PIC16F877A UART Reception
« on: January 07, 2011, 10:56:39 AM »

Offline clarkent

  • Lead Acid Battery
  • *******
  • Posts: 505
  • Pogi/Ganda Points: 20
  • Gender: Male
  • iehs
Re: Assembly code for PIC16F877A UART Reception
« Reply #1 on: January 07, 2011, 01:06:19 PM »
up
if you think you can or think you can't, you're probably right -h.ford

Philippine Electronics Forum

Re: Assembly code for PIC16F877A UART Reception
« Reply #1 on: January 07, 2011, 01:06:19 PM »

Offline Kaizer03

  • Nuclear Reactor
  • ****
  • Posts: 4847
  • Pogi/Ganda Points: 225
  • C#<-->Android<-->Java
    • PhilRobotics
Re: Assembly code for PIC16F877A UART Reception
« Reply #2 on: January 07, 2011, 01:11:42 PM »
^

would you mind to share your schematic?
Lend a hand for those who are in need!=)

Stop Hijacking!=) More Technical Posts!=)
 ;)

Kaizer Killer EX Pre-Alpha

Philippine Electronics Forum

Re: Assembly code for PIC16F877A UART Reception
« Reply #2 on: January 07, 2011, 01:11:42 PM »

Offline clarkent

  • Lead Acid Battery
  • *******
  • Posts: 505
  • Pogi/Ganda Points: 20
  • Gender: Male
  • iehs
Re: Assembly code for PIC16F877A UART Reception
« Reply #3 on: January 07, 2011, 01:52:02 PM »

ito po ang circuit ko sa proteus.


ito naman po yung schematic diagram ng hardware ko. ginamit ko lang yung mga available components ng proteus sa circuit na to.
if you think you can or think you can't, you're probably right -h.ford

Philippine Electronics Forum

Re: Assembly code for PIC16F877A UART Reception
« Reply #3 on: January 07, 2011, 01:52:02 PM »

Offline clarkent

  • Lead Acid Battery
  • *******
  • Posts: 505
  • Pogi/Ganda Points: 20
  • Gender: Male
  • iehs
Re: Assembly code for PIC16F877A UART Reception
« Reply #4 on: January 07, 2011, 01:57:26 PM »
nevermind the reset-button n the 2nd figure. napress lng yan nung nagprintscreen ako.hehe
if you think you can or think you can't, you're probably right -h.ford

Philippine Electronics Forum

Re: Assembly code for PIC16F877A UART Reception
« Reply #4 on: January 07, 2011, 01:57:26 PM »

Offline clarkent

  • Lead Acid Battery
  • *******
  • Posts: 505
  • Pogi/Ganda Points: 20
  • Gender: Male
  • iehs
Re: Assembly code for PIC16F877A UART Reception
« Reply #5 on: January 07, 2011, 03:25:34 PM »
up
if you think you can or think you can't, you're probably right -h.ford

Offline toasted siopao

  • She loves me, she loves me not, she loves me...
  • Global Moderator
  • Gas Turbine
  • *****
  • Posts: 2575
  • Pogi/Ganda Points: 107
  • Gender: Female
    • TeknoBlogger
Re: Assembly code for PIC16F877A UART Reception
« Reply #6 on: January 07, 2011, 03:56:15 PM »
Short mo RTS and CTS.

Offline motion55

  • Technical People
  • Diesel Generator
  • *****
  • Posts: 1882
  • Pogi/Ganda Points: 244
  • Gender: Male
  • Been at this longer than you've been alive.
Re: Assembly code for PIC16F877A UART Reception
« Reply #7 on: January 07, 2011, 05:04:45 PM »
Walang crystal sa PIC sa schematics? Your config code shows XT_OSC. This requires a 4MHz crystal to get the right baud rate.

Also, diba may capacitors sa C1 and C2a and C2b pins?

Here is my initial scan of your code:

Quote
Receive:   
;   clrf RCREG
   btfss PIR1,RCIF     ;check for received data
      goto Receive
      movf RCREG,W     ; copy the received data from RCREG to W
      return

I commented out the part which may prevent you from receiving.

Let me share a code snippet for receiving that I had been using. When there is a receive error the PIC's UART stops receiving and so the error has to be cleared.

Code: [Select]
;-----------------------------------------------------------
DO_RX:
         BTFSS    RCSTA,OERR
         GOTO     DO_RX2
;
         BCF      RCSTA,CREN
;
         MOVF     RCREG,W     ; Purge the fifo
         MOVF     RCREG,W     ; Purge the fifo
;
DO_RX2:
         BTFSS    RCSTA,CREN
         BSF      RCSTA,CREN
;-----------------------------------------------------------
DO_RX3:
         BTFSS    PIR1,RCIF
         GOTO     DO_RX3
;
         MOVF     RCREG,W
;
         RETURN
;-----------------------------------------------------------
"Set your mind free!"

Offline clarkent

  • Lead Acid Battery
  • *******
  • Posts: 505
  • Pogi/Ganda Points: 20
  • Gender: Male
  • iehs
Re: Assembly code for PIC16F877A UART Reception
« Reply #8 on: January 08, 2011, 12:48:22 PM »
thnx sir motion55, d best ka tlga pagdating sa assembly.hehe 4MHz po ang gamit kong osc.

sir glenjoy, maya pag uwi ko itatry ko din yan sa hardware ko.

2 pts =)
if you think you can or think you can't, you're probably right -h.ford

Offline clarkent

  • Lead Acid Battery
  • *******
  • Posts: 505
  • Pogi/Ganda Points: 20
  • Gender: Male
  • iehs
Re: Assembly code for PIC16F877A UART Reception
« Reply #9 on: January 11, 2011, 02:47:06 PM »
i tried the advice of sir motion and sir glenjoy. my project is finally working. lastweek ko sya napagana.hehe thnx

ung CTS and RTS ng DB9 shinort ko lang.
if you think you can or think you can't, you're probably right -h.ford

Offline luibog

  • Size AAA Battery
  • ***
  • Posts: 52
  • Pogi/Ganda Points: 1
  • Gender: Male
Re: Assembly code for PIC16F877A UART Reception
« Reply #10 on: January 22, 2011, 11:23:47 AM »
anong capacitor po ung gamit?

Philippine Electronics Forum

Re: Assembly code for PIC16F877A UART Reception
« Reply #10 on: January 22, 2011, 11:23:47 AM »

 

Privacy Policy

Contact Us: elabph@yahoo.com