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.

Problem with Keil C program

Status
Not open for further replies.

onde

Junior Member level 1
Junior Member level 1
Joined
Nov 29, 2002
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
88
keil c-Problem

hello!

I have a problem with the following program:
// Timerinterrupt

#include <reg517a.h>

void INTTIM0 (void) interrupt 1
{ if (P4 < 0x7f) P4 <<= 1;
if (P4 > 0x02) P4 >>= 1;
TH0=-39; // 10ms
TL0=0;
}

main()
{
P4 = 0x01;
TMOD = 0x01; // Timer 0 Mode 1 16 Bit
TH0 = -39; // every 10ms Int.
TL0 = 0;
ET0 = 1; // Timer 0 Interrupt disabled
EAL = 1; // enable all

TR0 = 1; //

while(1)
{
}
}

The Problem is, P4 is shifted only 1 time (from 0x01 to 0x10), after this nothing is happing.
Any Idea ???
 

not so clearly

what you mean that P4 swaps only once, for it to shift from 0x01 to 0x10 it MUST be shift FOUR times???
 

forgoten issue

You place both statments as an if, instead of blocking the statments as [if]
[else]
blocks.
I mean that in the next shift, P4 shift one time to the LEFT: 0x02 -> 0x04,
then the next if statment take place: P4 shift back to RIGHT: 0x04 -> 0x02.
The sequence occur each interrupt cycle.

Change the statment to [If] [else] block!
 

Hi,

thx for your answere and for you hint :)
aua, I think it´s not my day.
bye
 

an other thing:
even if my compiler accepts
while (1)
{
}

I write:
while (1)
{
;
}


also had bad experience with:
{
blablabla...

goto xyz_label;

blablabla...

xyz_label:
}

one of the compilers I'm using wanted to see the ";" between the label and the bracket


thomaz
 

C-problem

Hello onde,

Please describe your problem clear, so other people can help you.
Your problem isn't a compiler or even ke*l problem.
I guess you wish to realize a constant and repeatedly shift through P4.
If so, you have to register wether the two shift events reach there bounderies. If so, register and turn around the shift direction.

Please post for more details.

Robby
 

Hi,

if you put th second condition in an ELSE statment, you will get the seceuence: 1, 2, 4, 8, 16, 32, 64, 128, 64, 128, 64, 128 ... and so on, because you have to decideif you are Up-shifting or Down-Shifting. Sometihg likethis wil go well,

unsigned char UP = 1;

void timer0 interrupt() using 1{

if (UP)
if ( (P4 <<= 1) < 0x80 ){
UP = 0;
}
else
 

Hi,

if you put th second condition in an ELSE statment, you will get the seceuence: 1, 2, 4, 8, 16, 32, 64, 128, 64, 128, 64, 128 ... and so on, because you have to decideif you are Up-shifting or Down-Shifting. Sometihg likethis wil go well,

unsigned char UP = 1;

void timer0 interrupt() using 1{

if (UP)
if ( P4 < 0x80 )
P4 <<= 1;
else{
UP = 0;
P4 >>= 1;
}

else
if ( P4 > 0x01)
P4 >>= 1;
else{
UP = 1;
P4 <<= 1;
}

............... Rest of routine
}
 

the Optimized Code as follows:

#define true 1
#define false 0

typedef bit bool;

bool UP = 1;

void timer0 interrupt() using 1
{
if (UP && P4<0x80)
P4 <<= 1;
else if(UP)
{
UP = 0;
P4 >>= 1;
}
else if (P4 > 0x01)
P4 >>= 1;
else
{
UP = true;
P4 <<= 1;
}
}
 

Hello onde,

In my opinion, your problem may comes some usage restriction.
P4 is declared in reg517a.h as of below.
sfr P4 = 0xE8;

In my case, whenever I use the special funcion register(sfr),
I use the replace variable of unsigned char type.

#include <reg517a.h>

void INTTIM0 (void) interrupt 1
{
unsigned char IO=0;

IO = P4;
if (IO < 0x7f) {
IO <<= 1;
P4 = IO;
}
if (IO > 0x02) {
IO >>= 1;
P4 = IO;
}
TH0=-39; // 10ms
TL0=0;
}

main()
{
P4 = 0x01;
TMOD = 0x01; // Timer 0 Mode 1 16 Bit
TH0 = -39; // every 10ms Int.
TL0 = 0;
ET0 = 1; // Timer 0 Interrupt disabled
EAL = 1; // enable all

TR0 = 1; //

while(1)
{
}
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top