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