PDA

View Full Version : Pic16c745



cuitesun
- 24th September 2010, 02:39
Hi does anyone here knows how to light up the LED using MPLAB software but the code is C+.below is my code i try but i am stuck ,i think i am wrong somewhere as i am very weak in programming so i need guardian it will be greatly appreciated if you can help me.I have to put in the code into the microchip to make the LED light up .I also ask around do i need to use timer 2 interrupt to write in the while loop?i not sure how to do that.




#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;



RB2 = 0x0;

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

ScaleRobotics
- 24th September 2010, 04:06
There are a ton of people that are on this forum to escape having to think about C. You might try a C forum, and they might be more help.We just have a lot of examples in PicBasic.

cuitesun
- 24th September 2010, 07:24
scalerobotics I don't think you should say escape .Programming is not like a one day thing which you can possibly know it well.People just need guardian and help .I did some research too,No one is perfect ,if you so good at it, is that any useful links for that? i admit i am programming nerd. Please mind your words.thank you.

Acetronics2
- 24th September 2010, 10:20
. Please mind your words.thank you.

Hi, Cuitesun

The problem is NOT you being a nerd or else or not ...

asking that here is same as ask it the " Merlion " or Jurong Falls birds ( ahaaaa .... )

Their answers will be something " life is water " or "Lucy in the sky " ( the songs ).

Shorly told, nobody or so here uses ( or wants to use ...) C, even C+ ...

I just doubt any Port pin will take 4 as a value, for anything else the bug might be in your config line ... ( never seen "H4" as a parameter nor ... as it is 16 bits coded )

Now ....
You would have much more answers aboard the Microchip forum ... if you use a Microchip compiler : is that a decent answer ??? ;)

Alain

ScaleRobotics
- 24th September 2010, 20:12
Sorry cuitesun, I did not mean to offend anyone. Just trying to keep our PicBasic forum on topic. We could start to (try) to discus C, C++, Fortran, Java. And I am sure some of our members are well versed on other topics as well. But that really was not what this site is intended for. That is why we suggest going to a site whose members specialize in the subject of your inquiry.