Hi everyone is my first time here i really really need help ,i am stuck in the code c+ to light up a Led using PIC16C745, 6mhz oscillator. I don't understand why doesn't it light up ): tell me if there is a mistake thanks.
below is my code:
#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 = 0x1;
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;
}
}
}
below is my code:
#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 = 0x1;
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;
}
}
}