Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Need help to correct PIC16F88 USART coding

Status
Not open for further replies.

pietro10

Junior Member level 1
Joined
Mar 15, 2010
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,405
usart

hello

a person could look my code for me correcting my mistake
Part-mail works
the code must be operated in the mode USART receiving PIC16F88, 9600 / s, 8 data bits, no parity bit, 1 Stop bit No hyperterminal software flow control
diode + resistor is connected to portRA1 and lights if the capital letter B and A is pressed to turn it off


Code:
; Utilisation de l'USART du 16F88 avec interruption
; 9600 bauds/s     8 bits de données     Pas de bit de parité
; 1 bit de STOP    Pas de contrôle de flux

; 2010

; version 1.0
; microcontrôleur PIC 16F88
; développé avec Microchip MPLAB IDE
 ERRORLEVEL -302 ;remove message about using proper bank ERRORLEVEL -302; 
 List p=16F88 ; processeur utilisé 
 #include <p16F88.inc>

         __CONFIG          _CONFIG1, _CP_OFF & _CCP1_RB3 & _DEBUG_OFF & _WRT_PROTECT_OFF & _CPD_OFF & _LVP_OFF & _BODEN_OFF & _MCLR_ON & _PWRTE_ON & _WDT_ON & _HS_OSC
 __CONFIG _CONFIG2, _IESO_OFF & _FCMEN_OFF

;xxxxxx
; macro
;xxxxxx

bank1 macro  ; passage en banque 1
  bsf STATUS,RP0 
  bcf STATUS,RP1
  endm

bank0 macro  ; passage en banque 0
  bcf STATUS,RP0
  bcf STATUS,RP1
  endm

;xxxxxxxxxxxxxxxxxxxxxxxxx
; déclaration de variables
;xxxxxxxxxxxxxxxxxxxxxxxxx

 CBLOCK H'070'  ; début de la zone des registres d'usage général du 16F88
    

 STATUS_TEMP : 1  ; sauvegarde du registre STATUS (routine d'interruption)
 W_TEMP : 1    ; sauvegarde du registre W  (routine d'interruption)
 donnee : 1    ; 8 bits de données 
 pointerDonnee: 1
 ENDC 

;xxxxxxxxxxxxxxxxxxxx
; démarrage sur reset
;xxxxxxxxxxxxxxxxxxxx

 org 0x0000
 goto initialisation

; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
; Routine d'interruption 
; 1 source d'interruption : réception (USART)
; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 org 0x0004     ; vecteur d'interruption

 movwf W_TEMP 
 swapf STATUS,W
 movwf STATUS_TEMP  ; sauvegarde du registre W puis du registre STATUS

    bank1
    btfss PIE1, RCIE
    goto suite
    bank0
    btfsc PIR1, RCIF
    goto reception 
suite
 goto restauration

reception
    bank0
    movlw pointerDonnee
    movwf FSR
    movf RCREG , W ; le flag RCIF est remis à 0 par une lecture du registre RCREG
    movwf INDF ; les 8 bits de données sont transféres dans un registre d'usage général

 
  ; xxxxxxxxxxxxxxxxxxxxxxxxxxx
  ; test d'une erreur d'overrun
  ;xxxxxxxxxxxxxxxxxxxxxxxxxxxx


 btfss RCSTA , OERR
 goto restauration; traitement de l'erreur d'overrun
 bcf RCSTA , OERR ; on efface le bit OERR
 bsf RCSTA , CREN ; on relance la réception
 goto restauration

restauration

 swapf STATUS_TEMP,W  ; restauration des registres STATUS puis W
 movwf STATUS 
 swapf W_TEMP,f
 swapf W_TEMP,W

 retfie  

;xxxxxxxxxxxxxxx
; initialisation
;xxxxxxxxxxxxxxx

initialisation   

 bank0 
 clrf PORTA   ; mise à 0 des sorties du port A
 clrf PORTB   ; mise à 0 des sorties du port B
 movlw 0x70   ; B'111 0000' on efface la memoire
 movwf FSR
init
 clrf INDF
 incf FSR,f
 btfss FSR,3  ; B'111 1111'
 goto init

 
 
 bank1
 movlw B'11111101'
 movwf TRISA

 ; bit 1 du port A (RA1) = 0 : configuration en sortie (LED )
 


 movlw B'00100100'
 movwf TRISB

 ; bit 5 du port B  = 1 : configuration en entrée (TX : USART)
 ; bit 2 du port B  = 1 : configuration en entrée (RX : USART)
 
 
 movlw B'01100000';horloge 4MHZ quartz
 movwf OSCCON  


movlw B'00000111'; RBPU      b7  : 0= Résistance rappel +5V en service
movwf OPTION_REG  ; INTEDG    b6 : 1= Interrupt sur front montant de RB0
                              ;                0= Interrupt sur front descendant de RB0
                              ; TOCS      b5 : 1= source clock = transition sur RA4
                              ;                0= horloge interne
                              ; TOSE      b4 : 1= Sélection front descendant RA4(si B5=1)
                              ;                0= Sélection front montant RA4
                              ; PSA       b3 : 1= Assignation prédiviseur sur Watchdog
                              ;                0= Assignation prédiviseur sur Tmr0
                              ; PS2/PS0   b2/b0 valeur du prédiviseur
                  ;           000 =  1/1 (watchdog) ou 1/2 (tmr0)
                              ;           001 =  1/2               1/4
                              ;           010 =  1/4                     1/8
                              ;           011 =  1/8                     1/16
                              ;           100 =  1/16                     1/32
                              ;           101 =  1/32                     1/64
                              ;           110 =  1/64                     1/128
                              ;           111 =  1/128             1/256
     

 movlw B'00000111';configurer le mode 111 pour utiliser RA0 RA1 RA2 RA3 en I/Ovation des comparateurs analogiques
 movwf CMCON   
                        

 movlw B'01000000'; GIE       b7 : masque autorisation générale interrupt
 movwf INTCON    ;                ne pas mettre ce bit à 1 ici
                  ;                sera mis en temps utile
                              ; PEIE      b6 : masque autorisation générale périphériques
                              ; TMR0IE    b5 : masque interruption tmr0
                              ; INTE      b4 : masque interuption RB0/Int
                              ; RBIE      b3 : masque interruption RB4/RB7
                              ; TMR0IF    b2 : flag tmr0
                              ; INTF      b1 : flag RB0/Int
                              ; RBIF      b0 : flag interruption RB4/RB7
 
   
 movlw B'00100000'; RESERVED  b7 : réservé, laisser à 0 
 movwf PIE1           ; ADIE      b6 : masque interrupt convertisseur A/D
                              ; RCIE      b5 : masque interrupt réception USART
                              ; TXIE      b4 : masque interrupt transmission USART
                              ; SSPIE     b3 : masque interrupt port série synchrone
                              ; CCP1IE    b2 : masque interrupt CCP1
                              ; TMR2IE    b1 : masque interrupt TMR2 = PR2
                              ; TMR1IE    b0 : masque interrupt débordement tmr1




    movlw D'25'
    movwf SPBRG ; (SPBRG) = D'25'

    movlw B'00000100'
    movwf TXSTA
    ; bit 7 (CSRC) = 0 (non utilisé : 0 par exemple)
    ; bit 6 (TX9) = 0 (non utilisé : 0 par exemple) 
    ; bit 5 (TXEN) = 0 (non utilisé : 0 par exemple)
    ; bit 4 (SYNC) = 0 : mode asynchrone
    ; bit 3 = 0 (non implémenté)
    ; bit 2 (BRGH) = 1 : mode asynchrone haute vitesse
    ; bit 1 (TRMT) = 0 (non utilisé : 0 par exemple)
    ; bit 0 (TX9D) = 0 (non utilisé : 0 par exemple)

 bank0 
 
 movlw B'10010000' 
 movwf RCSTA 
 ; bit 7 (SPEN) = 1 : utilisation du port série 
 ; bit 6 (RX9)  = 0 : 8 bits de réception
 ; bit 5 (SREN) = 0 (non utilisé : 0 par exemple) 
 ; bit 4 (CREN) = 1 : autorise la réception 
 ; bit 3 (ADEN) = 0 (non utilisé : 0 par exemple) 
 ; bit 2 (FERR) = 0 (en lecture seule) 
 ; bit 1 (OERR) = 0 (en lecture seule) 
 ; bit 0 (RX9D) = 0 (non utilisé : 0 par exemple)
 clrf donnee
 clrf pointerDonnee
movlw donnee
movwf pointerDonnee
 



    bank1
    bsf PIE1 , RCIE ; autorisation de l'interruption de réception de l'USART
    bsf INTCON , PEIE ; autorisation des interruptions des périphériques
    bsf INTCON, GIE ; autorisation globale des interruptions 

 bank0

 goto debut_programme  
  
;xxxxxxxxxxxxxxxxxxxxx
; programme principal
;xxxxxxxxxxxxxxxxxxxxx

debut_programme
 
 movlw B'01000001'     ; (code ASCII de A= B'0100 0001')
 subwf donnee,W  
 btfsc STATUS,Z  
 goto afficheA    ; donnee = 'A'

 movlw B'01000010'     ; (code ASCII de B= B'0100 0010')
 subwf donnee,W  
 btfsc STATUS,Z  
 goto afficheB    ; 
 goto debut_programme 
 afficheA
 bcf PORTA,1;RA1 est aux 0VDC si on appuis sur la touche A
goto debut_programme
afficheB  
bsf PORTA,1;RA1 est aux 0VDC si on appuis sur la touche B
goto debut_programme ; on attend l'interruption de réception (USART)




 END
 

Hi,

understanding of an assembly code is quiet difficult than a c code. can you shift your programing language from assembly to c. if yes then there are a lot of support available on internet regarding source codes for PIC series

try following for C code

12F675 : RS232 Serial transmitter the code is retargetable to any PIC

https://www.best-microcontroller-projects.com/pic-serial-port.html

Serial LCD module the code is retargetable to any PIC with a built in USART

https://www.best-microcontroller-projects.com/serial-lcd.html

usart pic
 

thank you for your link

I got the error when jumping on the reception
Code:
Reception
    bank0
    movlw pointerDonnee "error replace movf pointerDonnee"
    movwf FSR
    movf RCREG, W; ROTI the flag is reset to 0 by reading the register RCREG
    movwf INDF; the 8 bits of data are transferred to a general purpose register

but why not stay portA1 to +5 VDC after pressing the uppercase letter B keyboard???
 

Hi,

You say you are getting that Error - but what program is giving that kind of error message and correction ??

Have just built you code in Mplab v 8.46 and it is error free - are you running it in a simulator program ??
 

hello
I'm using MPLAB IDE v6.6 + + HYPERTERMINAL my card homade 16F88 + max232
there is no error LED lights up when I press the Shift key "B"
but the LED does not stay lit and I want to turn it off by pressing the Shift "A" on your keyboard
<<are you running it in a simulator program ??>>
No I'm not using simulation
Clean: Deleting intermediary and output files.
Clean: Deleted file "m16f88_serie_final.err".
Clean: Deleted file "C:\My Music\m16f88_serie_final.cod".
Clean: Deleted file "C:\My Music\m16f88_serie_final.hex".
Clean: Deleted file "m16f88_serie_final.lst".
Clean: Deleted file "C:\My Music\rc.mcs".
Clean: Done.
Executing: "C:\Program Files\MPLAB IDE\MCHIP_Tools\mpasmwin.exe" /q /p16F88 "m16f88_serie_final.asm" /l"m16f88_serie_final.lst" /e"m16f88_serie_final.err"
Warning[203] C:\MY MUSIC\M16F88_SERIE_FINAL.ASM 137 : Found opcode in column 1. (movlw)
Warning[203] C:\MY MUSIC\M16F88_SERIE_FINAL.ASM 138 : Found opcode in column 1. (movwf)
Warning[203] C:\MY MUSIC\M16F88_SERIE_FINAL.ASM 213 : Found opcode in column 1. (movlw)
Warning[203] C:\MY MUSIC\M16F88_SERIE_FINAL.ASM 214 : Found opcode in column 1. (movwf)
Warning[203] C:\MY MUSIC\M16F88_SERIE_FINAL.ASM 234 : Found opcode in column 1. (movlw)
Warning[207] C:\MY MUSIC\M16F88_SERIE_FINAL.ASM 244 : Found label after column 1. (afficheA)
Warning[206] C:\MY MUSIC\M16F88_SERIE_FINAL.ASM 246 : Found call to macro in column 1. (bank1)
Warning[203] C:\MY MUSIC\M16F88_SERIE_FINAL.ASM 247 : Found opcode in column 1. (bcf)
Warning[206] C:\MY MUSIC\M16F88_SERIE_FINAL.ASM 248 : Found call to macro in column 1. (bank0)
Warning[203] C:\MY MUSIC\M16F88_SERIE_FINAL.ASM 249 : Found opcode in column 1. (goto)
Warning[207] C:\MY MUSIC\M16F88_SERIE_FINAL.ASM 250 : Found label after column 1. (afficheB)
Warning[206] C:\MY MUSIC\M16F88_SERIE_FINAL.ASM 252 : Found call to macro in column 1. (bank1)
Warning[203] C:\MY MUSIC\M16F88_SERIE_FINAL.ASM 253 : Found opcode in column 1. (bcf)
Warning[206] C:\MY MUSIC\M16F88_SERIE_FINAL.ASM 254 : Found call to macro in column 1. (bank0)
Warning[203] C:\MY MUSIC\M16F88_SERIE_FINAL.ASM 255 : Found opcode in column 1. (goto)
Loaded C:\My Music\m16f88_serie_final.COD
BUILD SUCCEEDED: Thu Jul 22 11:33:42 2010
 

Hi,

Well first thing, if possible, goto microchips site and download MPlab IDE V8.53.
**broken link removed**
Uninstall the old Mplab before installing th new version. Save your data files /projects just in case, though they should be retained.


Its advisable to keep your projects withing the C...\Microchip\ folder rather than in your Music etc.

You should then correct the warning messages by moving those lines to column 2, so that you get a clean build.

Without running the software in hardware or a simulator is hard to say what the error is; it would perhaps be easier if we could see the full project, hardware etc.
Can you give the link to the original project so we can see how its intended to run.



Executing: "C:\Program Files\Microchip\MPASM Suite\MPASMWIN.exe" /q /p16F88 "Harry.asm" /l"Harry.lst" /e"Harry.err" /d__DEBUG=1
Executing: "C:\Program Files\Microchip\MPASM Suite\mplink.exe" /p16F88 "Harry.o" /u_DEBUG /z__MPLAB_BUILD=1 /z__MPLAB_DEBUG=1 /m"Harry.map" /w /o"Harry.cof" /x
MPLINK 4.35, Linker
Copyright (c) 1998-2010 Microchip Technology Inc.
Errors : 0

Loaded C:\Program Files\Microchip\Harry\Harry.cof.
----------------------------------------------------------------------
Debug build of project `C:\Program Files\Microchip\Harry\Harry.mcp' succeeded.
Language tool versions: MPASMWIN.exe v5.35, mplink.exe v4.35
Preprocessor symbol `__DEBUG' is defined.
Thu Jul 22 10:51:58 2010
----------------------------------------------------------------------
BUILD SUCCEEDED
 

my project has nothing of interest to a 16F88 a alime 5VDC LED + resistance on portRA1 PIC16F88
MAX232 and connect capacitors on the RX portBA2 portB5TX PIC 16F88
have you understood my code?
I just want to know how to keep my LED lit?
 

Hi,

Have had chance to look at the code in more detail.

Basically it sits there cycling around this bit of code -

Code:
;xxxxxxxxxxxxxxxxxxxxx
; programme principal
;xxxxxxxxxxxxxxxxxxxxx

debut_programme
	
	 
	 movlw B'01000001'     ; (code ASCII de A= B'0100 0001')
	 subwf donnee,W 
	 btfsc STATUS,Z 
	 goto afficheA    ; donnee = 'A'
	
	 movlw B'01000010'     ; (code ASCII de B= B'0100 0010')A	 subwf donnee,W 
	 btfsc STATUS,Z 
	 goto afficheB    ;
	 goto debut_programme
afficheA
	 bcf PORTA,1;RA1 est aux 0VDC si on appuis sur la touche A

	goto debut_programme
afficheB 
	bsf PORTA,1;RA1 est aux 0VDC si on appuis sur la touche B
	goto debut_programme ; on attend l'interruption de réception (USART)

Until some data is received the program will just bypass switching the led on or off.

When data is sent to the 16F88, it is supposed to Interrupt the system into the Receive RS232 Data mode and then place the received character into the register 'donnee'

It would seem this is not happening either for your hardware or my simulator, so must assume there is a fault in that part of the code.

Debugging all of that would take me some time and you will learn nothing.

You might be better doing a simpler system where it just sits there until the data is received and then compared in one operation without using the interrupt system which is quiet complicated even for regular users.

Tutorial 7a from that link of Nigels will do that and readily work on your 16F88 chip - the code is good as I have used it myself.

Still suggest you update your really old Mplab to V8.53 as soon as.
 

Hi,


Have a go with this code which simply waits for the next character to be received rather than using the interrupts.

Have run it on a simulator and the led toggles on and off with an A and B .
 

hello WP100

thank you for the code
 

hello
I can not turn off the diode with hyperterminal
I tried to control the peak with a program in C + SDL interface with Windows XP but I can not turn off the LED if I pressed 2!
16F88 + diode rouge sur port ra1 max232 clock4MHZ
 

Attachments

  • projet C+asm.zip
    614.2 KB · Views: 80

Hi,

Well had to double check the dates of your posts - its a year since your last one ??

A serial link is generally an easy project so think you must be getting something basic wrong somewhere.

Think you better post your new code and a diagram of your whole circuit so we can see what things are like now.
Perhaps you can also post your old Assembler code which I assume you could not get to work.

Also, are you using a Pickit2 programmer ?
 

Hi,

Could not see any circuit diagram of what you are using.

Have just run this simple code which just outputs ' Hello ' all the time.
It runs with the chips internal oscillator, it just needs your rs232 chip connecting up and it should work.
Set Hyperterminal to 9600, 8bit, No parity, 1 stop bit, Flow control - none

See if you can establish proper communications with the pc using this.
 

Attachments

  • rs232.rar
    1.6 KB · Views: 78

hello

I had to work hard this week
and I do not have time for answer these message
I use a homemade programmer **broken link removed**
but I not did find an update of bootlder for use the 16F883
i not used my pc this week
and this fonctionne program finally, the lights diode
I do not understand why I the works could not turn off my led?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top