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.

urgently need help in PIC16C745

Status
Not open for further replies.

cuitesun

Newbie level 4
Joined
Sep 27, 2010
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,326
Hi everyone i am stuck with my code using c+ to make the LED light ,below is the code ,i think there is something wrong somewhere can you guide me will be greatly appreciated :)

I am using PIC16C745 6Mhz osciallator but i don't know why it doesn't light up? when i burn the code into my mircochip ):



#include <htc.h>
//#include "delay.h"
__CONFIG(WDTDIS & PWRTDIS & UNPROTECT & H4);


void init(void)
{
PORTB = 0x02;
TRISB = 0x02;
}
void InitUSART(void)
{
TXSTA = 0x22;
RCSTA = 0x90;
SPBRG = 0x9b;
}

void enter(void)
{
while(!TRMT);
TXREG = 0x0d;
}

void tx_start(void)
{
while(!TRMT);
TXREG = 0x1a;
}

void send_msg(const char *str)
{
char ps;
ps = *str;
while(ps>0)
{
str++;
if (ps== 0) break;
while(!TRMT);
TXREG = ps ;
ps = *str;
}

}


void main(void)
{
init();
InitUSART();

while (1)
{

if(RB1 == 0)
{
RB2 = 0x01;
RB3 = 0x04;

send_msg("at+cmgf=1");
enter();
DelayMs(50);
send_msg("at+cmgs=");
send_msg("+6582543453");
enter();
DelayMs(50);
send_msg("hello");
tx_start();
DelayMs(5000);

RB2 = 0x0;

}
else if(RB1==1)
{
RB2 = 0x0;
RB3 = 0x0;
}
}
}
 

Have you check compiling with other codes like blinking LED or other codes with your compiler? It might not be your codes problem but your compiler set up issues.
 

Firstly when you begin to code do initialize the ports whether input or output by configuring the TRIS bits of the corresponding ports to 1 or 0.Only after that you should move a value to the port.Then if you are using hexadecimal value to be outed to the port,use it correctly.For eg you have written:

RB2 = 0x0;
RB3 = 0x0;

This is not the correct way of representing a hexadecimal number.Either use 0 or 0x00.
If you are using Mikro C,then the way of writing a delay is:

Delay_ms(1000) for 1 sec delay.
Please do correct the above mistakes & see whether the code is working or not.
Regards,
Jerin. :)

---------- Post added at 04:44 ---------- Previous post was at 04:41 ----------

Also if you are using library functions please do search for it @ Qhelp window,understand its purpose & then implement it rite?
Regards,
Jerin. :)

---------- Post added at 05:12 ---------- Previous post was at 04:44 ----------

Can you just say me what was your intention behind the above code?
Regards,
Jerin.
 

I am suppose to write in this code using c+ using MPLAB and then burn into the micro chip using PICSTART PLUS.This code is by previous student who did this project but i try to put in the mircochip and it didn't works i mean the led didn't light up .I try many methods and it doesn't response ): i will try out wat u had told me thanks .
 

i read up the book and it said what causes led not lighting - got one i not sure is "check PWN Output? with an oscilloscope or logic probe i don't know wat is PWN? is it the pin configuration?
 

PWM = pulse width modulation

There is a specific pin to do that but it can be done in any input/output pins
 

ok i try and see how it goes ^^
 

Ya. Just check the pin output on the oscilloscope.............
Regards,
Jerin.
 

from the codes you are using serial port right? Desktop serial or laptop usb to serial cable? If its the laptop version, then i would suggest you to test the cable by shorting pin 2 and pin 3 and see whether it echoes back to the pc.

---------- Post added at 09:28 ---------- Previous post was at 09:22 ----------

Since you are not using the library to set up your USART, you need this:

SPEN RX9 SREN CREN — FERR OERR RX9D (pg 78) page 77 to 89 from the datasheet would be handy.

---------- Post added at 09:30 ---------- Previous post was at 09:28 ----------

Also check whether your clock is set to 6MHz. Somebody who have used the chip before might change the setting default. (pg 100 datasheet).
 

hey thanks alot will try it out and tell u how is the progress .
 

You might also want to check the Baud rate generator setting( pg 79 datasheet). Typically people set it to 9600 and both receivers and transmitters has to be at that rate. Wrong baud rate will either gives you no output, weird characters ort even missing or extra characters.
 

Ya. Tat also can be a reason for not working!!!!!!!
Regards,
Jerin.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top