Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Pic16c745 help??

Status
Not open for further replies.

cuitesun

New Member
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;
}
}
}
 
Everything to this point looks ok. See below for what needs some attention.
Code:
void main(void)
{
init();
InitUSART();

while (1)
{

if(RB1 == 0)                           //Is this a switch? There's no debounce routine.
{
RB2 = 0x1;                              //Invalid value for a single bit, can be 0x00 or 0x01 only
RB3 = 0x04;                            //Same issue here.

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)                      //Here you're assigning a value to RB1, you need to use
{                                            //else if(RB1==1)
RB2 = 0x0;
RB3 = 0x0;
}
}
}

I hope you have an emulator or flashable version of the chip, testing on a OTP chip could get costly.
 
Pic16c745

Hi LTX71CM tks for your response .I will look into it and try it out.But mine is using MPLAB software and PICSTART plus to burn my code into the microchip .
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top