Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

desperate need of help urgent with microcontrollers

Status
Not open for further replies.

Vandal S

Member level 3
Joined
May 2, 2009
Messages
54
Helped
3
Reputation
6
Reaction score
1
Trophy points
1,288
Activity points
1,749
uart1_read mikroc

i need urgent with a problem that i can't undestand. i am a beginner so you can expect that i made huge errors, but please help me because i have an exam in a couple of days

i wrote a program in mikroc, which gets a character by USART and starts 4 leds (actually there are 2 motors, but for the simplicity i removed that circuit). i used interrupts and delays.
the problem is that if i limit the current to a very low value, even the leds don't light, but they blink rapiddly according to my program. so they work ok.
but if i increase the current, they behave strangely. i press (as it is pc controlled) to go left and it remains in left. the same is for right. i press up, it randomly activates left, then a little back so the motors stops, then up again.. i haven't seen a perfect pattern, just that most of the time (not always) left and right are activated at the right time, but they stay forever.
i don't think it's a rf problem (there are rf modules between pc and pic 16f877) because at very low current (<50mA) they blink as they should.
the program i think is good, because in proteus works

it could be that it's not filtered enough? but i put 2 capacitors at the 7805, 2 at the oscillator..

please, once again, help me with an ideea, something. at least to know the cause, if not to solve it.
 

char byte_read, i = 0, flag = 0;
unsigned short cnt = 0;
#define Dir PORTD
#define front 0b00000001
#define left 0b00000010
#define back 0b00000100
#define right 0b00001000
#define Stop 0b00000000
#define backleft 0b00000110
#define backright 0b00001100
#define frontleft 0b00000011
#define frontright 0b00001001

void interrupt ()
{
PIR1.TMR1IF = 0;
if (PIR1.RCIF)
{
byte_read = UART1_READ();
flag = 1;
}
} end interrupt


void main ()
{
unsigned short j;
TRISD = 0;
INTCON.PEIE = 1;
T1CON = 1;
PIE1.RCIE = 1;
PIE1.TMR1IE = 1;
INTCON.GIE = 1;

UART1_Init(1200);

while(1)
{
if (flag ==1)
{switch(byte_read)
{
case 'W':{
Dir=front;
flag=0;
delay_ms(420);
break;
}
case 'S':{
Dir=back;
flag=0;
delay_ms(420);
break;
}

...



}
}
if (flag==0)
Dir=Stop;
}
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top