Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

[Moved]: can any one help me out for software uart for pic18f452 .

Status
Not open for further replies.

karthims

Newbie level 5
Joined
Sep 15, 2014
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
chennai
Activity points
74
Actually i am using pic18f452 as well as Hitech C18 compiler IDE MPLABX.I tried many times for Software uart myself but cant able to achieve that.So i am asking your help please be need full friends.
Thanks in advance for your help.

Ic-pic18f452
Crystal -10mhz
Compiler-Hitech C18
IDE-MPLABX
 

paulfjujo

Advanced Member level 4
Joined
Jun 9, 2008
Messages
1,390
Helped
280
Reputation
560
Reaction score
268
Trophy points
1,363
Location
France 01800
Activity points
9,719
hello,

Show us what you allready did ...

This piece of code just to put you on the rails.. (done for a 18F252 but must be compliant..)

Code:
//gestionnaire d'interruption
//------------------------------
// High priority interrupt vector
#pragma code InterruptVectorHigh = 0x08
void InterruptVectorHigh (void)
{
  _asm
    goto InterruptHandlerHigh //jump to interrupt routine
  _endasm
}


// High priority interrupt routine
#pragma code
#pragma interrupt InterruptHandlerHigh
void InterruptHandlerHigh ()
{
  static char i ; // doit etre statique pour conserver sa valeur entre les IT
  static char C ;
  static int T;
//======== SERIAL======================
if(PIR1bits.RCIF) // si un car arrive
   {
   C =ReadUSART(); // le lire => RAZ  RCIF
   if(RCSTAbits.FERR || RCSTAbits.OERR)
     {
      RCSTAbits.CREN = 0 ;
      RCSTAbits.CREN= 1 ;
     }
    // if you want an Echo 
     while(BusyUSART()); // par sécurité
     WriteUSART(C); 

     if( C == BS)  // correct the buffer (Back Shift)
        {
         if(i>0){
             i--;  }
        }
      else {
      if(C != CR && i<MAX_LEN)   // if not <CR> touch or size less than maximum of buffer 
      {
        buffer[i++]=C ; // store it into the buffer
        }else
        {
         buffer[i]='\0'; // fin de chaîne si CR
         i=0;
         received =1;  // flag to test inside the main .. for displaying the result on LCD or Terminal
       }
      }
    }
}
use UART library..
read explanations ...on MPLAB_C18_Libraries_51297f.pdf

not usable like this
need init of many parameter
buffer size..etc ..
lets'go.
 

Vbase

Full Member level 6
Joined
Apr 7, 2015
Messages
367
Helped
74
Reputation
148
Reaction score
72
Trophy points
28
Activity points
1,997
There is no Hi-Tech C18 Compiler. Hi-Tech made PICC and PICC-18 Compilers. Microchip made C18 Compiler.

So, are you using C18 Compiler ? with MPLAB X ?
You can download for free and use XC8 with MPLAB X, it is a C compiler for 8 bits PICs, it is a new version of HI-TECH PICC and PICC-18 Compilers together.
 

karthims

Newbie level 5
Joined
Sep 15, 2014
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
chennai
Activity points
74
First of all Thanks to all for your quick reply...

Actually i am the new one to micro controllers.I just tried by the UART protocol logic like start bit=high,stop bit=low . I cant able to develop that, so i have no snippet for my code.

I tried like as saeedsolutions.blogspot.com but it is not working for me.


My compiler -HI-TECH PICC18-PRO.

Is there any possibilities to do software uart using XC8..? if so just let me know any material or pages to support
 

milan.rajik

Banned
Joined
Apr 1, 2013
Messages
2,528
Helped
540
Reputation
1,078
Reaction score
523
Trophy points
1,393
Activity points
0
The Software UART code at saeedsolutions.blogspot.com work fine. I have tested it myself. I have also ported it to PIC18F and it works fine. I have not tested with PIC16F. Please zip and post your complete MPLAB X Hi-Tech PICC-18 project files. I will test it.
 

karthims

Newbie level 5
Joined
Sep 15, 2014
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
chennai
Activity points
74
This is my code...I referred http://saeedsolutions.blogspot.in/


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//***It is for reception ***//
 
#include <htc.h>
 
//#pragma config CONFIG1H = 0x22
__CONFIG(1, OSC_HS & OSCS_OFF);
//#pragma config CONFIG2L = 0xF
__CONFIG(2, PWRT_OFF & BOR_ON & BORV_20);
//#pragma config CONFIG2H = 0xE
__CONFIG(3, WDT_OFF & WDTPS_128);
//#pragma config CONFIG3H = 0x0
__CONFIG(4, CCP2MUX_OFF);
//#pragma config CONFIG4L = 0x80
__CONFIG(5, STVR_OFF & LVP_OFF);
//#pragma config CONFIG5L = 0xF
__CONFIG(6, CP0_OFF & CP1_OFF & CP2_OFF & CP3_OFF);
//#pragma config CONFIG5H = 0xC0
__CONFIG(7, CPB_OFF & CPD_OFF);
//#pragma config CONFIG6L = 0xF
__CONFIG(8, WRT0_OFF & WRT1_OFF & WRT2_OFF & WRT3_OFF);
//#pragma config CONFIG6H = 0xE0
__CONFIG(9, WRTC_OFF & WRTB_OFF & WRTD_OFF);
//#pragma config CONFIG7L = 0xF
__CONFIG(10, EBTR0_OFF & EBTR1_OFF & EBTR2_OFF & EBTR3_OFF);
//#pragma config CONFIG7H = 0x40
__CONFIG(11, EBTRB_OFF);
 
 
#define Transmitter RC0
#define Receiver RC1
#define Transmitter_dir TRIC0=0
#define Receiver_dir    TRIC1=1
 
#define _XTAL_FREQ 10000000 //10MHz
#define BitCount          8
#define Baudrate              9600    //Baud rate
#define OneBitDelay           (2500000/Baudrate)
 
 
unsigned char UART_Receive(void)
{
    unsigned char DataValue = 0;
    while(Receiver==1);
 
    __delay_us(OneBitDelay);
    __delay_us(OneBitDelay/2); 
 
    for ( unsigned char i = 0; i<BitCount; i++ )
    {
        if ( Receiver == 1 )
        {
            DataValue += (1<<i);
        }
 
        __delay_us(OneBitDelay);
    }
 
    if ( Receiver == 1 )
    {
        __delay_us(OneBitDelay/2);
        return DataValue;
    }
    else                      //some error occurred !
    {
        __delay_us(OneBitDelay/2);
                return 0;
    }
}
 
void PORT_INIT()
 {
   Transmitter;
   Receiver;
   Transmitter_dir;
   Receiver_dir;  
 }

 
Last edited by a moderator:

karthims

Newbie level 5
Joined
Sep 15, 2014
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
chennai
Activity points
74
If you have any snippet or working code that will be more useful for me....
Thank you
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top