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.

Embedded C program code

Status
Not open for further replies.

rajathirajan

Newbie level 1
Joined
Oct 18, 2011
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,288
Hi ..... am using MPLAB V8 and Hitech C Compiler , I dont know how to configure fuses in the programs, and i also write the code in serial program but i con't get out from that program can any send the sample program...or pls correct and send the program..

#include<pic.h>
__CONFIG( HS & WDTDIS );
void main()
{
unsigned char mybyte[]="WELCOME";
unsigned int i=0;
TXSTA=0x24;
SPBRG=64;
SPEN=1;
while(1)
{
TXREG=mybyte;
while(TXIF==0);
i++;
}
}
 

Can try this code:

Code:
#include<htc.h>
#define _XTAL_FREQ 20e6
__CONFIG(0x3F3A);
void uart_init()
{
    TRISC6=0;
    TXSTA=0b00100100;    //CHECK THE DATA SHEET FOR TXSTA
    RCSTA=0b10010000;    //SEE THE DATA SHEET FOR RCSTA
    BRGH=0;            //  low baud rate 
    SPBRG=129;      //baud rate 2400
}

void interrupt_enable()
{
    GIE=1;
    PEIE=1;
    RCIE=1;
}

void txd(char write_data)
{
    TXREG = write_data;
    while(!TRMT);
}

void interrupt UART()  //interrupt service routine
{    
    PORTD = RCREG; //simply to get the received ASCII on PORTD
}



main()
{      
        TRISD=0;
        uart_init();
        interrupt_enable();
	txd('W');   
	txd('E');  
	txd('L');    
	txd('C');   
        txd('O');
	txd('M');
	txd('E');  //DISPLAY "WELCOME" at starting 
      
        while(1);    //WAITING FOR INTERRUPT (SEE RESULT ON PORT D)
    
}


---------- Post added at 11:17 ---------- Previous post was at 10:57 ----------

to configure fuse with in code,
just follow this steps:

1> In MPLAB, >> configure >> Configuration bits
2> Select required configuration and get the 16 bit code corresponding to that
3>Now put the code in your program as below.
Code:
__CONFIG(0x3F3A); //here the configuration bits value is 3f3a in hex[CODE]
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top