Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
November 01, 2024, 12:59:25 00:59


Login with username, password and session length


Pages: [1]
Print
Author Topic: pic Serial communication  (Read 5027 times)
0 Members and 1 Guest are viewing this topic.
shahzaib198
Guest
« on: January 21, 2008, 06:14:13 18:14 »

Well Can any one tell me how to make a Serial Communication with
pic16f84a? I know many will answer it as that it does not have the capability but how to  create that. Pls tell me the code in Microbasic or Micro C

I know how to connect max232 with 16f84

help me how to set baud rate in Micro basic or Micro C

thanks in Advance

ShahZaib
Logged
Silent_Thunder
Junior Member
**
Offline Offline

Posts: 69

Thank You
-Given: 56
-Receive: 20



« Reply #1 on: January 22, 2008, 06:53:31 06:53 »

Hi
it is easy to use the soft UART, simply read the help file and u'll find very simple.
any way here is a sample code copied from the manual, hope that helps


program soft_uart_test
dim received_byte, er as byte

main:
  Soft_Uart_Init(PORTB, 1, 2, 4800, 0)    ' Initialize soft UART
  while true
    do
      received_byte = Soft_Uart_Read(er)  ' Read received data
    loop until er = 0
    Soft_Uart_Write(received_byte)        ' Send data via UART
  wend
end.

Regards
Logged
hell_pk
Guest
« Reply #2 on: January 22, 2008, 07:38:44 07:38 »

This will get u started.I used pic basic pro to program & used easy PIC 4 dev system.


' PicBasic Pro program to send and receive from the hardware serial port
'used comm1 seetings of 8N1 with flow control= none,cable used was provided by mikroelektronika.
'jumber settings on board were RC7=Rx (jp7) & RC6=Tx (jp8)
DEFINE      OSC 8
Define  LCD_DREG        PORTD   ' Define LCD connections
Define  LCD_DBIT        4
Define  LCD_RSREG       PORTD
Define  LCD_RSBIT       2
Define  LCD_EREG       PORTD
Define  LCD_EBIT        3
   

Lcdout $fe, $80, " By  hell_pk"
Pause 1500
Lcdout $fe, $1




DEFINE HSER_RCSTA 18h

DEFINE HSER_TXSTA 98h
DEFINE HSER_BAUD 2400

'DEFINE HSER_SPBRG 51 

'DEFINE HSER_CLROERR 1

TRISC = %10111111             ' Set TX (PortC.6) to output
        SPBRG = 51                      ' Set baud rate to 2400
        RCSTA = %10010000             ' Enable serial continuous receive
        TXSTA = %00100000             ' Enable transmit asynchronous mode
       

char   var   byte      ' Storage for serial character
'char="a"

loop:   Hserout ["Hello World", 13, 10]   ' Send text followed by carriage return and linefeed

   Hserin [char]   ' Get a char from serial port

   Hserout [char]      ' Send char out serial port
lcdout $fe, $80, "RECEIVE = ", char
   Goto loop      ' Do it all over again

   

Logged
Silent_Thunder
Junior Member
**
Offline Offline

Posts: 69

Thank You
-Given: 56
-Receive: 20



« Reply #3 on: January 22, 2008, 11:03:54 11:03 »

hi hell_pk
your code is fine, but it uses a hardware serial witch the 16f84 does not have, so software UART must be used in this case
Logged
Kafao
Newbie
*
Offline Offline

Posts: 10

Thank You
-Given: 1
-Receive: 0


« Reply #4 on: January 25, 2008, 08:52:22 20:52 »

Yes. Try to use something like 16F628 with the same pinout.
Logged
Kabron
Active Member
***
Offline Offline

Posts: 198

Thank You
-Given: 64
-Receive: 144



« Reply #5 on: January 26, 2008, 02:04:44 14:04 »

You can use Interruptdriven SoftUart code from my PIC Serial Sniffer project:
http://www.sonsivri.com/forum/index.php?topic=10147.0
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC