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.

[SOLVED] Rs232 in PIC16F84A with assembly code

Status
Not open for further replies.

vishy71

Full Member level 2
Joined
Dec 16, 2010
Messages
126
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
Iran
Activity points
2,296
Hi
after months i get back to ask some question from my dear friends.
here is my problem!actually it is not problem i just wanna check it and know youre idea
I wanna send and recieve characters max232 and make serial comunication between PIC16f84A and computer.

can u give me example plz?
with assembly code!

tnx
 

You'll need a softUART, due to the fact the 16F84A does not have a hardware UART.

I have several compatible versions in C, I'll see if I can find one in Assembly.
 
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
Attached is a PDF discussing implementation of a softUART for baseline PICs in Assembly. You should be able to modify the code for the midrange 16F series.
 

Attachments

  • software_uart.pdf
    118.8 KB · Views: 388
Hi,

Yes we haven't heard from you for a while..

You will find full details of the software usart here PIC Tutorial* Seven - RS232 - should work fine on the 84A.

If you are communicating with another pic or micro you do not need a Max232 chip if the distance is just a couple of meters.
If you are connecting to a PC then you do need to use a Max232 to match up the voltage levels.

---------- Post added at 21:09 ---------- Previous post was at 21:05 ----------

Attached is a PDF discussing implementation of a softUART for baseline PICs in Assembly. You should be able to modify the code for the midrange 16F series.

Hi bigDOGguru

Beat me to it:-D - nice tutorial - any connection DataDOG Systems ?
 
Hi
thanks all
I must try it in fact.i will back
thanks for every thing
;-)
 

Hi every body
how is every thing wp100?

in max232 we must use 1uf.can we use 1uf for ic pins and use another capacitor for voltage?
thanks
 

Hi,

Would use all 5 of the 1uf caps rated at 16 or 25v, including the voltage rail one, mounted close to the max232 pins, regardless of what you may have further up the +5v line.

Be careful when ordering your chip, the Max232 needs 1uf caps, the Max232A needs 0.1uf

Have you got your code working ok ? do you use a simulator to help prove your software / hardware ?

Not sure what programmer you have but if its the Pickit2 it has a Usart tool to help you test your rs232 code without a pc connected.
 
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
hi

my code works good.it can get data from pc without using max232 but it can't send data
i have max232.i make it's circuit but i have just 4 caps (1uf) and i need another.
see here:
VDD
|---------->to max232
|
--- 1uf -------> can i use for example 2.2uf?
---
|
|
------
--- GND
-
 

Hi,

Not sure about its value, I expect it will be something to do with the ripple produced by the max232 internal voltage doublers etc.

Give it a try, doubt 2u2 or 4u7 will damage anything ..
 
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
Is this any help? it is how I use it.

Max232.jpghttps://obrazki.elektroda.pl/10_1310236238.gif
 

Attachments

  • Max232.gif
    Max232.gif
    3.5 KB · Views: 146
Last edited:
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
Hi my freineds
i back to ask from you that can u say how can I config USART in PIC16F628A?
I understand something from it's datasheet but it is not enough.it is enough if you say steps for do this.
thanks
 

Hi,

Hows it going .. did you get the rs232 working on the 84A ok ?

For the 628A you can also use your software Usart like the 84A, but you now have the inbuild Usart hardware so its even easier to use.

That Pic tutorial has a Hardware Usart example at the very end, version 7.7. for a 876 chip
There is a reference in the notes to change a line for a 628A chip.

To give you exact Usart set up details you need to say what osc frequency you are using and what baud rate you want to use.
Assume you are using the inbuilt internal osc at 4meg ?
 

Hi
no it is not ok

:-(

i try it may be for 20 but it dosn't work!i think it may be depend on my programe but it is ok

I wanna try Usart in pic16f628a!inbuild
tnx
 

Hi,

I assume you have tried sending the data to and from the 84A to the PC via a max232 ?

There are a few things you can get wrong apart from the code, like cable and max232 chip connections. Did you use the correct size capactitors for the version of the Max232 chip you have ?

Again assume you are testing things in hardware, if you post your code perhaps I can try it in a simulator to prove its ok and help identify where the error is.

If I get time later I will test out a Usart routine for the 628A as well, but again need to know what oscillator frequency you are using and what baud rate as these must be specified in the code.
 
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
Hi,

Here is a working example for a 628A chip, its taken from my controllers code which uses the same routine.
 

Attachments

  • USART_628A.rar
    75 KB · Views: 120
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
Hi,

Here is a working example for a 628A chip, its taken from my controllers code which uses the same routine.


Hmm.. didn't seem to attach the file ... should be here now - well its re appeared in the earlier post ? - think the site is getting screwed up again ..?
 

Attachments

  • USART_628A.rar
    75 KB · Views: 99
  • Like
Reactions: vishy71

    vishy71

    Points: 2
    Helpful Answer Positive Rating
Hi
I must try youre code my friend.thanks a lot.and I must read webs which dog have introduce to me.
for a while bye but here is my code
just serout and serin is my problem

include <p16f84a.inc>
__config _WDT_OFF & _PWRTE_OFF & _CP_OFF & _HS_OSC
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CBLOCK 0X0C ;;
Reg_1 ;;
Reg_2 ;;
Reg_3 ;;
COUNTER ;;
RCV ;;
LS ;;
bitc
ENDC ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
org 0x00 ;;
goto main ;;
main ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
BSF STATUS,5 ;;;;;;;;;;;;;;;;;;;;;
CLRF TRISB ;RB7 -->INPUT ;;
BSF TRISB,7 ;;
BCF STATUS,5 ;;;;;;;;;;;;;;;;;;;;;
BSF PORTB,6
CALL LCD_init ;;
MOVLW "T"
CALL LCD_CHR
MOVLW "o"
CALL LCD_CHR
MOVLW "h"
CALL LCD_CHR
MOVLW "i"
CALL LCD_CHR
MOVLW "d"
CALL LCD_CHR
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
CALL SERIN ;READ DATA ;;
CALL LCD_CHR
MOVLW "T"
CALL SEROUT
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
GOTO $-4 ;BACK TO READ AGAIN ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SERIN BTFSC PORTB,7 ;CHECK ;;
GOTO $-1 ;START BIT ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CALL DELAY52US ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MOVLW 0X08 ;;
MOVWF COUNTER ;;
BTFSC PORTB,7 ;CHECK ;;
GOTO SERIN ;START BIT;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CALL DELAY104US ;;
BTFSC PORTB,7 ;;
BSF STATUS,C ;;
BTFSS PORTB,7 ;;
BCF STATUS,C ;;
RRF RCV,F ;;
DECFSZ COUNTER,F ;;
GOTO $-7 ;;
MOVF RCV,0 ;;
RETURN ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;SEND DATA ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SEROUT MOVWF RCV
MOVLW 0X08
MOVWF COUNTER
BCF PORTB,6
CALL DELAY104US
RRF RCV,1
BTFSC STATUS,C
BSF PORTB,6
BTFSS STATUS,C
BCF PORTB,6
CALL DELAY104US
DECFSZ COUNTER,1
GOTO $-7
BSF PORTB,6
CALL DELAY104US
RETURN
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;DELAY ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DELAY52US ;;
movlw .33 ;;
movwf Reg_1 ;;
decfsz Reg_1,F ;;
goto $-1 ;;
nop ;;
NOP ;;
RETURN ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DELAY104US ;;
movlw .68 ;;
movwf Reg_1 ;;
decfsz Reg_1,F ;;
goto $-1 ;;
NOP ;;
RETURN ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DELAY1S ;;
movlw .93 ;;
movwf Reg_1 ;;
movlw .38 ;;
movwf Reg_2 ;;
movlw .11 ;;
movwf Reg_3 ;;
decfsz Reg_1,F ;;
goto $-1 ;;
decfsz Reg_2,F ;;
goto $-3 ;;
decfsz Reg_3,F ;;
goto $-5 ;;
nop ;;
nop ;;
RETURN ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;////////////////////////////////////////////////////////////////////////
;///////////////////////////////LCD.inc//////////////////////////////////
;////////////////////////////////////////////////////////////////////////
;//////////////////////////////8 bit LCD/////////////////////////////////
;////////////////////////////////////////////////////////////////////////
; //
; Amin Aghakhani //
; **broken link removed** //
; vishtaspahoraii@yahoo.com //
; //
;////////////////////////////////////////////////////////////////////////
;////////////////////////////////////////////////////////////////////////
; LCD port ----------> 74164 pinouts ----->CLC:RB1 & DATA:RB0//
; LCD_RS ----------> RB3 //
; LCD_E ----------> RB2 //
; Reg_1 ----------> use for delay //
; Reg_2 ----------> use for delay //
;////////////////////////////////////////////////////////////////////////
;////////////////////////////////////////////////////////////////////////
;intizaling LCD //
LCD_init ;//
movlw 0x30 ;8bit mode //
call LCD_CMD ;goto LCD_CMD //
movlw 0x30 ;8bit mode //
call LCD_CMD ;goto LCD_CMD //
movlw 0x30 ;8bit mode //
call LCD_CMD ;goto LCD_CMD //
movlw 0x38 ;8bit LCD mode //
call LCD_CMD ;goto LCD_CMD //
movlw 0x0f ;cursor blink //
call LCD_CMD ;goto LCD_CMD //
movlw 0x01 ;clear display //
call LCD_CMD ;goto LCD_CMD //
call delay1500us ;delay1500us //
return ;go back //
;////////////////////////////////////////////////////////////////////////
;////////////////////////////////////////////////////////////////////////
;send commands to LCD //
LCD_CMD ;//
movwf LS ;copy w to LS //
movlw 0x08 ;copy 0 to w //
movwf bitc ;copy w to bitc //
sendingcmd ;//
rlf LS ;rotate left LS //
btfsc STATUS,0 ;is C/1? //
bsf PORTB,0 ;yes so set RB0 //
btfss STATUS,0 ;no it's not equal 1 so is it 0? //
bcf PORTB,0 ;yes so clear RB0 //
call send_bit ;call send_bit //
decfsz bitc,1 ;decrease form bitc and check it not be 0 //
goto sendingcmd ;it's not 0 so goto sendingcmd //
bsf PORTB,2 ;not!bitc/0 so set RB2 or EN //
call delay800us ;delay800us //
bcf PORTB,2 ;clear EN //
return ;go back //
;////////////////////////////////////////////////////////////////////////
;////////////////////////////////////////////////////////////////////////
;send character //
LCD_CHR ;//
movwf LS ;copy w to LS //
movlw 0x08 ;copy 8 to w //
movwf bitc ;copy w to bitc //
sendingchr ;//
rlf LS ;rotate LS to left //
btfsc STATUS,0 ;is C/1? //
bsf PORTB,0 ;yes so set RB0 //
btfss STATUS,0 ;no! is C/0? //
bcf PORTB,0 ;yes so clear RB0 //
call send_bit ;sending_bit //
decfsz bitc,1 ;decrease from bitc and check it!is it 0? //
goto sendingchr ;no! so goto LCD_CHR //
bsf PORTB,2 ;yes! so set EN //
bsf PORTB,3 ;and RS //
call delay800us ;delay800us //
bcf PORTB,2 ;clear EN //
bcf PORTB,3 ;clear RS //
return ;go back //
;////////////////////////////////////////////////////////////////////////
;////////////////////////////////////////////////////////////////////////
;send bit to 74164 //
send_bit ;//
bsf PORTB,1 ;set RB1 //
nop ;a bit delay //
nop ;... //
nop ;... //
nop ;... //
bcf PORTB,1 ;clear RB1 //
bcf PORTB,0 ;clear RB0 //
return ;go back //
;////////////////////////////////////////////////////////////////////////
;///////////////////////////Delay routines///////////////////////////////
;////////////////////////////////////////////////////////////////////////
delay1500us ;//
movlw .48
movwf Reg_1
movlw .6
movwf Reg_2
decfsz Reg_1,F
goto $-1
decfsz Reg_2,F
goto $-3
nop
;//
return ;//
delay800us ;//
movlw .151
movwf Reg_1
movlw .3
movwf Reg_2
decfsz Reg_1,F
goto $-1
decfsz Reg_2,F
goto $-3
nop
nop ;//
return ;//
;////////////////////////////////////////////////////////////////////////
;////////////////////////End of file/////////////////////////////////////
;////////////////////////////////////////////////////////////////////////
END


I wanna use 8mhz and 9600bps in 628A
again
thanks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top