cuitesun
Newbie level 4
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;
}
}
}
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;
}
}
}