Discussion Forum

nid help on LED blinking

Next Thread | Thread List | Previous Thread Start a Thread | Settings

DetailsMessage
Read-Only
Author
james yeo
Posted
2-Dec-2008 04:21 GMT
Toolset
C51
New! nid help on LED blinking

i have problem with the led blinking. I using the exmaple program given by keil using uVision3. When i run the program, the LED on the development board didnt blink, it just stay on! wat should i do?

thanks!

Read-Only
Author
james yeo
Posted
2-Dec-2008 07:24 GMT
Toolset
C51
New! RE: nid help on LED blinking

i found out something, when i try to run the blink code that keil provide, I found that the parallel port 1(one) pins dosent have the tick jumping around. Is that the reason why the LED on the board does not blink? if thats the reason, what should i do to make it work?

Read-Only
Author
erik malund
Posted
2-Dec-2008 13:47 GMT
Toolset
C51
New! RE: nid help on LED blinking

a blink is often seen as 'lit'. if the blinking frequency is more than 50-120 Hz (depending on your eyes) you will not see a blink, but a lit LED

Erik

Read-Only
Author
james yeo
Posted
3-Dec-2008 00:17 GMT
Toolset
C51
New! RE: nid help on LED blinking

so so i slow down the blinking timing? or what can i do to see the led blinking?

the coding:

#include <REG8252.H>

void wait (void)
{ ;
}

void main (void) { unsigned int i; unsigned char j;

while (1) {
for (j=0x01; j< 0x80; j<<=1) { P0= j;

for (i = 0; i < 1000; i++) { wait (); } }

for (j=0x80; j> 0x01; j>>=1) { P0= j;

for (i = 0; i < 1000; i++) { wait (); } } }
}

Read-Only
Author
james yeo
Posted
3-Dec-2008 00:17 GMT
Toolset
C51
New! RE: nid help on LED blinking

sorry typo error, i mean so should i slow down the timing*

Read-Only
Author
james yeo
Posted
3-Dec-2008 00:30 GMT
Toolset
C51
New! RE: nid help on LED blinking

I think i better say what i do so that you guys can get a better picture. Firstly, I dl uVision3 and use one of its example, which is blinky project. I open taht project, compile it and run it. But nothing happen to my board LED which is integrated with the development board itself. Off course i have connect the board to the CPU already

Read-Only
Author
Per Westermark
Posted
3-Dec-2008 01:49 GMT
Toolset
C51
New! RE: nid help on LED blinking

I think it is better if you start by teaching your delay function to actually perform any delay.

And it may be a _very_ good idea to also read the instructions just above the text input box and make sure that you post your source code according to the instructions. Then we may be able to read your code.

Read-Only
Author
james yeo
Posted
3-Dec-2008 01:54 GMT
Toolset
C51
New! RE: nid help on LED blinking

my code:

/* BLINKY.C - LED Flasher for the Keil MCBx51 Evaluation Board with 80C51 device*/

#include <REG8252.H>


// When you have enabled the option Stop Program Execution with Serial
// Interrupt, the Monitor-51 uses the serial interrupt of the UART.
// It is therefore required to reserve the memory locations for the interrupt
// vector.  You can do this by adding one of the following code lines:

// char code reserve [3] _at_ 0x23;   // when using on-chip UART for communication
// char code reserve [3] _at_  0x3;   // when using off-chip UART for communication

void wait (void)  {                   /* wait function */
  ;                                   /* only to delay for LED flashes */
}

void main (void)  {
  unsigned int i;                     /* Delay var */
  unsigned char j;                    /* LED var */

  while (1) {                         /* Loop forever */
    for (j=0x01; j< 0x80; j<<=1)  {   /* Blink LED 0, 1, 2, 3, 4, 5, 6 */
      P1 = j;
                            /* Output to LED Port */
      for (i = 0; i < 10000; i++)  {  /* Delay for 10000 Counts */
       wait ();                       /* call wait function */
      }
    }

    for (j=0x80; j> 0x01; j>>=1)  {   /* Blink LED 6, 5, 4, 3, 2, 1 */
      P1 = j;                         /* Output to LED Port */
      for (i = 0; i < 10000; i++)  {  /* Delay for 10000 Counts */
       wait ();                       /* call wait function */
      }
    }
  }
}

i not sure whether to use port 0 or 1, but i have tried using both port and it still wont blink. Hope you guys can help me thanks alot!

Read-Only
Author
Per Westermark
Posted
3-Dec-2008 02:14 GMT
Toolset
C51
New! RE: nid help on LED blinking

I think it is better if you start by teaching your delay function to actually perform any delay.

Let's repeat: I think it is better if you start by teaching your delay function to actually perform any delay.

Don't you get it? Your delay function does not implement any delay! It is possible that the compiler will call it and immediately return. But just as possible that you won't even get any function call since your delay function does not have any side effect.

Question: How do you get your LED to flash slower?
Answer: You teach your delay function to actually perform a delay.
Suggestion how to do that: A huge number of suggestions available by using the search function in the upper right corner of this web page.

Read-Only
Author
james yeo
Posted
3-Dec-2008 02:28 GMT
Toolset
C51
New! RE: nid help on LED blinking

oo ok i get wat u mean! kk thx veri much

Read-Only
Author
james yeo
Posted
3-Dec-2008 05:56 GMT
Toolset
C51
New! RE: nid help on LED blinking

i try using for loop for delay, but it still cant work.

Read-Only
Author
Per Westermark
Posted
3-Dec-2008 07:41 GMT
Toolset
C51
New! RE: nid help on LED blinking

But if you had followed my advice and used the little search field in the upper right corner of this page, you would have known that you should not use a for loop to count time.

And you would also have found code that did implement delays without using a dumb for loop.

Read-Only
Author
I B Shy
Posted
3-Dec-2008 08:22 GMT
Toolset
C51
New! Almost definitely NOT what you want

  unsigned char j;                    /* LED var */

.
.
.

    for (j=0x01; j< 0x80; j<<=1)
    {
      .
      .
      .
    }

Because j is an unsigned char, the test for j<0x80 will always be true and you will never exit the loop.

Pass#1 j = 0x01
Pass#2 j = 0x02
Pass#3 j = 0x04
Pass#4 j = 0x08
Pass#5 j = 0x10
Pass#6 j = 0x20
Pass#7 j = 0x40
Pass#8 j = 0x80
Pass#9 j = 0x00
...
Pass#n j = 0x00

Read-Only
Author
I B Shy
Posted
3-Dec-2008 08:23 GMT
Toolset
C51
New! RE: Almost definitely NOT what you want

Whoops - Sorry - My mistake, I didn't read the code closely enough

Read-Only
Author
james yeo
Posted
4-Dec-2008 03:31 GMT
Toolset
C51
New! RE: nid help on LED blinking

is there any wrong with this code?

/* BLINKY.C - LED Flasher for the Keil MCBx51 Evaluation Board with 80C51 device*/

#include <REG8252.H>


// When you have enabled the option Stop Program Execution with Serial
// Interrupt, the Monitor-51 uses the serial interrupt of the UART.
// It is therefore required to reserve the memory locations for the interrupt
// vector.  You can do this by adding one of the following code lines:

 //char code reserve [3] _at_ 0x23;   // when using on-chip UART for communication
//char code reserve [3] _at_  0x3;   // when using off-chip UART for communication


void wait (void)  {                   /* wait function */
#define TF0_VECTOR 1

int R7=20;
TR0=0;
TF0=0;

TMOD=TMOD | 0xF0; //Timer 0,16 bit Timer
TMOD=TMOD & 0x01;

TL0=0xAF; //Timer 0, set 1 second
TH0=0x3C;
TR0=1; //start timer

while(R7!=0)
{
if(TF0!=0) //test if the timer overflow
{
TR0=0; //stop timer
TF0=0; //clear the overflow flag
R7--;
TR0=1;
}
}
                             /* only to delay for LED flashes */
}

void main (void)  {
  unsigned int i;                     /* Delay var */
  unsigned char j;                    /* LED var */

  while (1) {                         /* Loop forever */
   for (j=0x01; j< 0x80; j<<=1)  {   /* Blink LED 0, 1, 2, 3, 4, 5, 6 */

          P1 = j;
                    /* Output to LED Port */
      for (i = 0; i < 10; i++)  {  /* Delay for 10000 Counts */
       wait ();                       /* call wait function */
      }
    }

    for (j=0x80; j> 0x01; j>>=1)  {   /* Blink LED 6, 5, 4, 3, 2, 1 */
      P1 = j;
                                /* Output to LED Port */
      for (i = 0; i < 10; i++)  {  /* Delay for 10000 Counts */
       wait ();                       /* call wait function */
      }
    }
  }

}
Read-Only
Author
shyam T
Posted
3-Dec-2008 10:39 GMT
Toolset
C51
New! RE: nid help on LED blinking

hi

Read-Only
Author
james yeo
Posted
4-Dec-2008 02:13 GMT
Toolset
C51
New! RE: nid help on LED blinking

O ok because i have search some of the thread that says that using loop will do the job. But after that I try to search again and found out that having loop wont do as well as timer.

I am now using AT89S8252, product code is EQ-8051-ST1 which come with the development board and a programmer board. at the development board there are 8 LED, can these LED be control by the coding that I have done. Or is there other way other than blinking, can test out whether the board is working fine. I would prefer with C code.

Thanks You

Read-Only
Author
Per Westermark
Posted
4-Dec-2008 10:17 GMT
Toolset
C51
New! RE: nid help on LED blinking

1) Do not use the name wait() for your function. All it tells is some magic waiting (is expected to) happen, but not what wait. Waiting for a key press? Waiting for the supply voltage to stabilize? Waiting a specific time?

Since you are talking about a time delay, change the name so that it clearly says exactly how long the delay is. Optionally modify it to take a parameter to specify how many such time "clicks" the function will wait.

For example:

delay_10ms(25);  // Delay 250 ms
delay_1s(20);    // Delay 20 seconds
delay_us(2700);  // Delay 2700 us

2: You normally don't encapsulate all use of a timer into the delay function. You often initializes the timer once from main() and then you either use the timer in free-running mode, or clears the counter value ... (depending on how you choose to impelement the delay and the capabilities of the timers in your specific processor) in the delay function.

You want a delay function to have as little setup time as possible so that it may also contain a loop to handle n delay steps. With a lot of initial setup, the length of the first and the following ticks may be different.

Read-Only
Author
jelly been
Posted
4-Dec-2008 11:23 GMT
Toolset
C51
New! Talking of ill advised function names ...

Just seen some code written by one of my co-workers.

He had a line:

   if (AvaSpace())      // maintain link

I asked him what it was doing, maybe 'maintaining a link'?

He ummed and arred for a while and then conceded that he didn't remember.

So we looked at the function itself (the one that he had written only two days ago!).

It determines whether there is enough space in an internal buffer to store a data record.

I then realised what the name was suggesting ...

Have A Space ?

I have now suggested to the management that he needs some urgent training!

Read-Only
Author
Tamir Michael
Posted
4-Dec-2008 12:04 GMT
Toolset
C51
New! RE: Talking of ill advised function names ...

Now they even write software using SMS language?!

Read-Only
Author
Per Westermark
Posted
4-Dec-2008 15:05 GMT
Toolset
C51
New! RE: Talking of ill advised function names ...

I think his intended name (before shorening it was) AvailableSpace?

But a name AvailableSpace() sounds like a function that tells exactly how much space. A function EnoughSpace() - or better EnoughSpaceForRecord() - focuses more on the actual problem at hand: Is it possible to insert (at least) one more record?

With old development tools, the linker had severe limitations on the number of significant characters in an external symbol. This isn't a problem with modern tools. It takes extra time to write a longer symbol name, but the support cost (or at lesat total life-time cost) may be ten times the original implementation cost. So spending a little bit of extra time with very good symbol names do help.

I looked at some code yesterday. A function with a bool parameter named "bit". It really did not help me understand what the parameter did. The next function did take a parameter "protocol". It took me some time to figure out that this parameter selected tcp or udp for a transfer. Helpful symbol names are really vital - both for the sw quality and for the time it takes to maintain or extend/modify an existing software.

Read-Only
Author
jelly been
Posted
4-Dec-2008 15:15 GMT
Toolset
C51
New! RE: Talking of ill advised function names ...

"I think his intended name (before shorening it was) AvailableSpace?"

Unfortunately you are not correct, he said "have a space" was probably what he meant - But he couldn't actually remember!!??

Yes, I certainly agree with your comments - A little initial though can save a lot of time later on.

Read-Only
Author
erik malund
Posted
4-Dec-2008 15:42 GMT
Toolset
C51
New! function names and comments

A fully descriptive function name sometimes becomes unamangble e.g SeeIfThereIsRnoughSpaceReturnFalseIfnotTrueIfThereIs();

so while I am all in favor of descriptive funtion names the REAL place for describing a function is in the function header like

//////////////////////////////////////////
//
// FUNCTION U1 CheckSpace(U8 CSP_Csize)
//
// verify that there is enough space for CSP_Csize in RS232 output buffer
// returm TRUE if there is, FALSE if not
//

then if you have ANY question about a function look at the header

likewise sometimes a construct with many variables makes it 'impossible' to describe the variables and thus a definition of a variable should always be commented.

Erik

Read-Only
Author
Per Westermark
Posted
4-Dec-2008 16:20 GMT
Toolset
C51
New! RE: function names and comments

The function header comment can document the behaviour and reason. But the name must be meaningful since you can't spend 100% of your time cross-reference the function comment. Some editors picks up Doxygen or Javadoc comments and can show them when you hold the mouse above a symbol name. But most editors can not...

You have to make a distinction between descriptive name and a sentence.

SeeIfThereIsRnoughSpaceReturnFalseIfnotTrueIfThereIs();

See If There Is... don't help with any meaning.

Return False If not True If... don't convey any extra meaning since the true/false concept is built into the language. It is just a question of making the symbol name use positive or negative logic, i.e. "IsAxx", "HaveXX" or "IsNotXX", "MissingXX", ...

The code should focus on "what", and the comments should help out with "why".

A delay_ms(10) answers the what. But a comment may be able to point that an external hardware needs at least 6ms settle time which indicates what may happen if the function parameter is decreased. Without a comment, it will not be meaningful to take a scope and verify the delay. A measured delay of 10.5ms (because of interrupts or other things outside of the code control) may represent a failure if I don't know if 10ms has hard tolerance requirements in both directions.

Read-Only
Author
erik malund
Posted
4-Dec-2008 16:30 GMT
Toolset
C51
New! RE: function names and comments

Per.

I dreamt up a long 'descriptive' name, It was just an example of the type of names I have seen when someone codes "in the other ditch".

The function header comment can document the behaviour and reason. But the name must be meaningful enough for someone working with the project since you can't spend 100% of your time cross-reference the function comment unless you are just dropped into something you have no idea of

in other words:
the function name shall be meaningful enough to convey what it does, but for deatails - in the few cases you need them - you have to go to the funtion header.

Erik

Read-Only
Author
Per Westermark
Posted
4-Dec-2008 16:55 GMT
Toolset
C51
New! RE: function names and comments

No, my answer was not critique about your suggested name, but a continuation trying to explain why people should not think that a long name equals a good name. Everything is about context. And why people should not think that foo() is an acceptable name as long as there is a one-page comment describing the foo() logic directly above the implementation.

Writing too much is a very common error - most people who send in their first school assignment are scared to death about software comments. So they document every single code line, completely duplicating the software function in two different languages - but often with the comments describing a previous version of the application :).

How many have seen the following assembly code?

MOV A,0   ; Set register A to zero


Might be ok in a book teaching assembler, where the example is intended to let the reader learn the mov instruction. But as a comment in a real program, it does not supply any extra information. The reader still don't know why it is important that A is zero. If A is used as index into a text string, it might help to tell the reader that "start from first char in string".

Read-Only
Author
Cpt. Vince
Posted
4-Dec-2008 17:35 GMT
Toolset
C51
New! RE: function names and comments

I shall take a section of the Rules for Code Monkeys book I wrote many years ago about "comments" to help others figure out what a comment is.

(Rules for Code Monkeys is an internal document like the coding guidelines you have there at work: that open copy right next to your keyboard).

************

Generally "Comments" can be categorized as Tactical, Strategic, or Theater-Level. (The Theater Level can be termed Theatrical, but in the "Theater of War" sense and not the Showboat sense).

Theatrical comments are typically found in the file's header, and shall describe the purpose of the module, and how it may fit in the theater of operations for the Computer Software Configuration Item (CSCI). The CSCI is known as the final 'executable' file.

Theatrical comments provide the reader a higher level of understanding of the software and typically reflect the Software Requirements Specification (SRS) from the coding standpoint. Theatrical comments can be found anywhere, and do not [currently] have a flower-box identifier to indicate such comments. The most obvious location is within the module header information.

Theatrical comments provide the reader with a wider conceptual view of the code module. Theatrical comments can be information about the system's environment like the OS, CPU, Memory, IDE, Versions, etc. While Strategic and Tactical are the dominant forms, Theatrical comments should be still be contained in all source code modules. Source code also includes batch files, linker support files, and anything else that is required to cleanly build the CSCI besides the cross-compiler itself. If the IDE requires startup files, then those too should also be considered source-code and commented accordingly.

Strategic comments describe what a section of code is supposed to accomplish. Strategic comments should be placed before the code section that implements the task. This includes the function header block. At the function block, these Strategic comments identify the scope of the function, the expected method of accomplishing the task, the passed parameters, the return value, and any special notes the software engineer should know about the function. These notes may include such items as measured execution times, atomicity, or any other code-centric information that the software engineer should be aware of when modifying the function.

The more common Strategic comment has an enclosed flower-box describing the intent behind the following code. The code itself should be clear enough through liberal and consistent white-space usage, and data-store (aka 'variable') name selection.

Strategic comments should precede most control flow operations, and alterations of CSCI states. (e.g. if(), else, while(), or the enabling of interrupts, or data-store assignments that implement what the code is supposed to do).

Strategic comments should be the primary and dominant form of commenting source code.

Tactical comments describes the specifics on how the code is implementing a task. Typically these tactical comments are on an end-of -line basis. (For 'C' it would use the double-slash // delimiters).

Tactical comments serve to enlighten the non-obvious behavior or method implemented, and not simply a re-statement of what the code performs:

    i = 0; // assign zero to i           <---- poor comment
    i = 0; // start indexing from zero   <---- a better comment


The over-use of tactical comments will result in source code that takes too long to read, and begins to devalue and hide the worth while comments. So the above example typically wouldn't be commented.

Tactical comments should be as detailed as needed to inform the programmer. The common used for Tactical comments is when describing the side effects of code implementation or when the code performs something that is not obvious to the standard or novice programmer. Always write on a level that is explanatory the reader, and never assume the reader is as competent as you think you are.

Enjoy,

--Cpt. Vince Foster
2nd Cannon Place
Fort Marcy Park, VA

Read-Only
Author
Cpt. Vince
Posted
4-Dec-2008 17:54 GMT
Toolset
C51
New! RE: function names and comments

I have a template of stuff, one of which is the function name template.

This has the elements that I think are important to source code. IMHO.

/*
**======================================================================
**      Function_Name       [catagory]   [spec tracking numbers]
**======================================================================
**
**  Function comments
**
**----------------------------------------------------------------------
**
**  Parameters Passed:      <void>
**  Parameters Returned:    <void>
**  Notes:
**
**----------------------------------------------------------------------
*/
void Function_Name( void )
{
    . . .
}

An example of implementing this template into the real world... well I made this up, but it is a typical construct...

/*
**======================================================================
**      Keil_Example           [ CALC ]     CSC8  CSU8.2.1  R4
**======================================================================
**
**  This function shall scan the array for the specified value, perform
**  the simple pattern masking for validation. Based upon that 'match'
**  compute and return it's corrilation factor.
**
**  Add more description text here to make it thorough enough, but not
**  too thorough that the code-monkey ignores the design documents.
**
**  It helps to make reference to the design doc
**  ( e.g. "reference table XYZ for details on return format" )
**
**----------------------------------------------------------------------
**
**  Parameters Passed:
**
**      u8   val   - value to search for within array
**      u32 *arry  - array to parse
**      u32  pmask - pattern mask for validation
**
**  Parameters Returned:
**
**      s16 - corrilation factor: internal fractional binary format
**
**  Notes:
**
**      CAUTION: Contains a polling loop with no safeguards to protect
**               from an infinite loop if the hardware fails!
**               (needs a time based break mechanism)
**
**          As of 04-Dec-08, this routine takes way too long.
**      Need to optimize the algorithm. Suspect the array indexing
**      is taking too long. FIX IT! -- Cpt. VF
**
**----------------------------------------------------------------------
*/
s16 Keil_Example( u8 val, u32 *arry, u32 pmask )
{
    . . .
}

Things like date created or author of the function, to me, are irrelevant, since the module header contains this information on when the module was edited and why... and who was responsible for the changes.

The repeated function name in my header is important, along with the tags 'category' and the document referencing labels. Although your IDE/editor might not explicitly state that it uses the DOS 'grep' function, it has the same result.

grep CALC *.c > calculations.lst
grep DIAG *.c > diagnostics.lst
grep UTIL *.c > utilities.lst
grep CSC *.c > requirements.lst
grep MUTATOR *.c > mutators.lst
grep ACCESSOR *.c > accessors.lst

Your document references allow you to quickly identify where in your source code *you think* you are fulfilling the requirement(s).

As far as naming conventions go, all will fail. Most fail equally well. Do what you think is right. You'll get better at it in time.

Hungarian is a total waste, so don't go down that path.

Naming conventions become important for accessors and mutators (crossing module boundaries), while the internals are far less important.

That delay_ms( 10 ) function looks to me like an internal (module specific) function. A more formal type function name to me would look like TimeBase_Delay( 10 ) where you might infer that the time base module contains this function, and you must look into it in order to know that the passed parameter is in milliseconds.

Don't get me wrong, I'm not advocating that cross-module accessors & mutators have start with the module name. That is up to you. I usually don't do that. But I do use Upper_Case function names as potential cross module functions while all lower_case function names are internal service types. That's just me and not something I advocate others implement in a coding standard.

It is not "TimeBase_Delay_ms( 10 )" for a reason: I would use this format:

TimeBase_Delay( DEBOUNCE_DELAY );

and in the definition of the constant, I would have determined the function needs (milliseconds), while the code that called the function knows that it must call a delay function, but not need to know the delay is in milliseconds, microseconds, or some fractional hour format.

The delay_ms( 10 ) is kind of missing the point: you are delaying 10 milliseconds for a reason: make that reason clear to the poor slob who must maintain your scrawlings:

delay( SCREEN_REFRESH_TIME );

Anyway, I've rambled on too much again.

--Cpt. Vince Foster
2nd Cannon Place
Fort Marcy Park, VA

Read-Only
Author
Per Westermark
Posted
4-Dec-2008 19:10 GMT
Toolset
C51
New! RE: function names and comments

It would be quite interesting the see the full code monkey rule set.

delay( SCREEN_REFRESH_TIME );


Swatting magic numbers and instead use constants is the next step up, when people have considered their use of symbol names and how to comment their code.

Doing the swatting first would probably result in:

enum {
    N = 17,  // N=18 seems a bit excessive.
    M = 12,  // Use 12.
    ...
};

wait(N); // need to wait

or possibly introducing broken defines:

#define M 12
#define N M+5

wait(N*1000); // us
Read-Only
Author
Cpt. Vince
Posted
4-Dec-2008 20:13 GMT
Toolset
C51
New! RE: function names and comments

#define N M+5
Always( always( always ) ) use parenthesis.

#define N   (( ((M)) + ((5)) )) // (over) (use) (them) (!)


Its in the book; on page( PARENTHESIS ) to be exact.

It would be quite interesting the see the full code monkey rule set.

Its basically standard stuff; a racy jacket, a steamy intro, the main characters are shallow, has a thin plot line, lots of typos, and has a dry, monotone-ish narration.

In the end you are either a satisfied or you're left needing more.

<excerpts from "Rules for Code Monkeys"...>

Thou shalt not use Hungarian Notation.

Thou shalt not use 'internet' code; unless an assignment is due,
and the teacher can't tell the difference anyway.

Thou shalt not kill (depending upon the project specifications)

Thou shalt not use the closing bracket ']' symbol without first
declaring allegiance to King Kong or saying several "Hail Fay Wray"s.

Thou shalt not ramble-on-and-on in forums.

etc.

You know, the standard stuff.

--Cpt. Vince Foster
2nd Cannon Place
Fort Marcy Park, VA

Read-Only
Author
Per Westermark
Posted
4-Dec-2008 22:00 GMT
Toolset
C51
New! RE: function names and comments

Yes, I know that you hate macros.

I felt that I had to write that example just because the people in most need of good advice about symbol names and sw comments are quite likely to do produce such #define'd constructs.

A #define'd expression without parentheses is definitely one of the mortal sins of programming - it doesn't matter if it is production code or just some test code.

Another is to hide the #define'd symbol by not using capital letters.

Or having a conditional #define that mucks up a dangling else. Or writing code that has a dangling else.

A define that makes use of a parameter more than once is also quite high up on the no-no list. And code that does call a #define while using ++, -- or similar modifying accesses on one or more of the parameters.

I haven't really decided what is the best way to get good developers.
- Huge quantities of information.
- Give people a bit of help into all kinds of traps and then have them learn why they got into the trap and how to avoid at least that speficic pot-hole in the future.

In the end, hands-on experience with problems is quite efficient. People tend to remember a broken nose far longer than they remember the text in a school book. And they don't doubt the real pain that results from doing something the wrong way. The trick is to not produce permanent damage so they switch to another profession, and not to produce permanent monetary loss.

Read-Only
Author
Tamir Michael
Posted
5-Dec-2008 07:04 GMT
Toolset
C51
New! RE: function names and comments

Thou shalt not kill (depending upon the project specifications)

captain, what about the three rules of robotics... ;-)

Read-Only
Author
Per Westermark
Posted
5-Dec-2008 08:56 GMT
Toolset
C51
New! RE: function names and comments

They will not be introduced until the positronic brain has been released.

By the way. Asimov later extended with a fourth rule about the good of the many, to avoid freezing and permanently destroyed positronic brains ;)

Read-Only
Author
Tamir Michael
Posted
5-Dec-2008 08:59 GMT
Toolset
C51
New! RE: function names and comments

and, of course, he later introduced the "zero law" as well.

Read-Only
Author
Tamir Michael
Posted
5-Dec-2008 09:00 GMT
Toolset
C51
New! RE: function names and comments

ho, you meant that one!

Read-Only
Author
Andy Neil
Posted
4-Dec-2008 22:56 GMT
Toolset
None
New! RE: Swatting magic numbers

Yes, I have seen

#define TEN 10
Read-Only
Author
Per Westermark
Posted
5-Dec-2008 00:33 GMT
Toolset
None
New! RE: Swatting magic numbers

Now that is a real beaut.

I just hope it was from a very bright student who wanted to be a bit cheeky with his teacher.

I once saw some source code where the person didn't realize that decimal and hexadecimal is just different presentations of the same number, and that the C compiler supports hexadecimal constants.

So the code contained:

#define HEX_00 0
...
#define HEX_A0 160
#define HEX_A1 161
...
#define HEX_FF 255


Good to have in case he needed a hexadecimal number and forgot how to translate to decimal :)

Or maybe he had seen one of the binary declarations that exists here and there, and not realized that a header file with:

...
BIN_0110_1001 0x69
BIN_0110_1010 0x6a
...


exists just because binary numbers aren't part of the standard language, while the compiler has very good hexadecimal support directly in the language standard.

Read-Only
Author
james yeo
Posted
5-Dec-2008 02:27 GMT
Toolset
C51
New! RE: function names and comments

So i have to use the delay function inorder for this to work? But how do I create a delay function with AT89S8252?

Next thing, How do i ensure that my development board is correctly connected other than using the blinking code for testing, are there any other code which i can use for testing?

Thirdly, I have use meridian software to connect the development board, But when i select COM1 port, the active light will go off and I cannot chose the device from the list. Is this normal?

The board that i am using is EQ-8051-ST1 is a AT89S8252 chip, which i see from the board.

Read-Only
Author
james yeo
Posted
5-Dec-2008 09:25 GMT
Toolset
C51
New! RE: PCW

About PCW, I want to know the hexa code for this thing so that i can configure the output of the port. Because I heard that I need to configure the port so that I can make the LED blink

Read-Only
Author
Per Westermark
Posted
5-Dec-2008 09:54 GMT
Toolset
C51
New! RE: PCW

What is PCW?

Your subject "RE: PCW" seem to imply a continuation of an earlier discussion, but PCW has not been mentioned anywhere earlier in this thread.

Are you talking about the PCW C compiler?

Read-Only
Author
Cpt. Vince
Posted
5-Dec-2008 15:12 GMT
Toolset
C51
New! RE: function names and comments

captain, what about the three rules of robotics... ;-)

If a 'robot' implements Asimov's three Laws, its OS was most likely written by Microsoft, Apple, or Ben & Jerry's All Natural Coding Company.

Elsewhere, especially in the despot 3rd world like North Korea, or any communist country, Asimov's Law wouldn't be coded up with zeal.

The real-world variation to Isaac Asimov three laws of robotics is
the "Kim Jung Mao Tse-Stalin" Three Laws of Robotics:

1. A robot may not injure a human being or, through inaction, allow a
   human being to come to harm.

2. All Robots are to comply with The Higher Utopian Government (THUG)

3. Rule 2 supersedes Rule 1.

My rule-book against [coding] radicals does have a Human Safety Factors Section. No reference to Isaac though.

--Cpt. Vince Foster
2nd Cannon Place
Fort Marcy Park, VA

Read-Only
Author
Tamir Michael
Posted
5-Dec-2008 15:16 GMT
Toolset
C51
New! RE: function names and comments

Vince,
You are the perfect warrior: Combining a poetic soul with cutting edge deadly accuracy...!

Read-Only
Author
Cpt. Vince
Posted
5-Dec-2008 15:43 GMT
Toolset
C51
New! RE: function names and comments

Thanks for the compliment (that helps with my 'ego troubles')

"cutting edge deadly accuracy"

You have no idea... oh, wait... here's some "Killer Apps" I wrote a while ago...

(No 8051s were harmed in the making of these films. If you are a Ti DSP fan, you might avert your eyes.)

(no, I don't work for Raytheon).

NOTE: 1.8MB video
http://www.raytheon.com/newsroom/feature/stellent/groups/public/documents/media/cms04_022892.wmv


CAUTION: LARGE FILE 36MB video...
http://www.raytheon.com/broadcasts/rtn_rms_ps_excalibur_video2.wmv

--Cpt. Vince Foster
2nd Cannon Place
Fort Marcy Park, VA

Read-Only
Author
Tamir Michael
Posted
5-Dec-2008 17:37 GMT
Toolset
C51
New! RE: function names and comments

Vince,
Is this the new GPS guided artillery shell? I saw a TV program about it (I this is was on Discovery Science but I am not sure). They said something about the very high angle it hits its target, so that the bad guys cannot hide behind buildings!

Read-Only
Author
Cpt. Vince
Posted
5-Dec-2008 18:29 GMT
Toolset
C51
New! RE: function names and comments

"Is this the new GPS guided artillery shell?"

There are several of these GPS guided/assisted gun-launched systems. XM982 was only one of the trail-blazers. Don't forget: it has to be designed to handle the 'Howitzer' launch and balloting forces--you've heard of rugged-ized computers?

"I saw a TV program about it"

Yes, they've been on "Future Weapons" and other History / Discovery channel shows. XM982 gets most of the limelight right now.

The first video is a munition that hasn't been on those shows: yet (that I know of).

Its funny how I'll watch these shows and be surprised that they're showing 'my stuff.' (There are huge teams of engineers working on these, I think we all take total ownership of these projects).

There is usually a few years of lag between development and 'public release.' It used to be a lot longer, now its only a few years---uh well for some projects.

The high-angle thing is just one of many possible capabilities of these types of rounds. They can alter their trajectories to help prevent the enemy from knowing the launch points. In addition (the video sort of shows this, but you'd have to know it) you can launch them at staggered times and places, yet they can hit the target(s) 'simultaneously'.

The first video has IR capability: it can hit a moving target, so the GPS helps get to the target area while the IR does the terminal maneuvering. (the convoy on-the-move can still be shelled).

"...hide behind buildings!"

That type of high angle of attack allows the bad-guy bunker between the tall buildings get nailed. ...without also taking out the hospitals, day-care centers, shopping mall, code-monkey diploma mills, etc.

--Cpt. Vince Foster
2nd Cannon Place
Fort Marcy Park, VA

Read-Only
Author
Tamir Michael
Posted
5-Dec-2008 20:03 GMT
Toolset
C51
New! RE: function names and comments

“I Am Become Death, The Shatterer Of Worlds"

Read-Only
Author
Tamir Michael
Posted
5-Dec-2008 20:19 GMT
Toolset
C51
New! RE: function names and comments

Vince,
I hope you were not offended by this famous quote. It was meant as a compliment! By the way, for the sake of the ill-informed, "I Am Become Death, The Shatterer Of Worlds" is a quote from the Bhagavad Gita, uttered by Robert Oppenheimer 63 years ago today, on the occasion of the first nuclear weapon's test in New Mexico. It just crossed my mind.

Read-Only
Author
Cpt. Vince
Posted
5-Dec-2008 20:42 GMT
Toolset
C51
New! RE: function names and comments

Gita outta here! No offense taken.

But don't give Oppenheimer a Baum rap. He ensured that the good guys (aka USA) had it first.

--Cpt. Vince Foster
2nd Cannon Place
Fort Marcy Park, VA

Read-Only
Author
james yeo
Posted
8-Dec-2008 12:18 GMT
Toolset
C51
New! RE: PCW

Hmm no such thing? So is there any hexa code for port 1 or 2 of the development board so that i can enable the port to send output to the LED

Read-Only
Author
erik malund
Posted
8-Dec-2008 13:35 GMT
Toolset
C51
New! RE: PCW

So is there any hexa code for port 1 or 2 of the development board so that i can enable the port to send output to the LED
depends on current requirements
depends on LED configuration
depends on ...

Erik

Read-Only
Author
Per Westermark
Posted
8-Dec-2008 14:12 GMT
Toolset
C51
New! RE: PCW

"So is there any hexa code for port 1 or 2 [...]"

I somehow get the impression that the language fools you. This is not similar to a "cheat code" or "access code" that you get from someone and that allows you to activate a new feature.

Hexadecimal numbers are just a different way of writing a number. No need to use hexadecimal numbers. An 8-bit port can handle a number between 0 and 255 (8 bits represents 2^8 = 256 states).

You must know what you have connected to different pins of a port. Then you must calculate what number to write to the port to tell if a pin is input or output. And you must calculate what pins to drive high or low. And you must calculate what pins you are interested in when reading a port.

Note that your processor pins may not require any special setting to change the individual pins between input or output. But your datasheet will tell you.

And you have still not told what your PCW is?

Read-Only
Author
Tamir Michael
Posted
8-Dec-2008 14:15 GMT
Toolset
C51
New! RE: PCW

And you have still not told what your PCW is?

Hell, maybe PSW (does it even exist on a C51...?)

Read-Only
Author
james yeo
Posted
9-Dec-2008 02:05 GMT
Toolset
C51
New! RE: PCW

Sorry it should be control word, not PCW. Hmm can tell me where to find the formular to calculate the whether the pin is input or output?

Read-Only
Author
Per Westermark
Posted
9-Dec-2008 02:22 GMT
Toolset
C51
New! RE: PCW

Yes. The formula is simple:

a*1 + b*2 + c*4 + d*8 + e*16 + f*32 + g*64 + h*128

You have eight bits. Each having a bit position, i.e. a value of 1, 2, 4, 8, 16, 32, 64 or 128. The datasheet will tell what happens if you write a one or a zero to the bit. And it will tell if the relevant port has a data direction register, or if it only supports a open-drain transistor with a weak pull-up.

Now add together the relevant bit values. You do not post and ask how to sum the money to pay at the cafeteria. No need to ask how to sum the individual bits for the I/O ports either. And you should also be able to find a huge amount of sample code that shows how to use port pins as inputs and/or outputs. How much time have you spent reading datasheets and code in the week since this thread started? You should be quite comfortable with this by now.

Read-Only
Author
james yeo
Posted
9-Dec-2008 03:48 GMT
Toolset
C51
New! RE: PCW

oo so this formula is a representation of CW right? which determine which port is input and which port is output rite? thanks alot!

Read-Only
Author
james yeo
Posted
9-Dec-2008 04:05 GMT
Toolset
C51
New! RE: PCW

i saw this digram on how control word works.
Link: http://www.sharpmz.org/mz-700/8255ovview.htm

It says that the bit can control which port to work. So do i need to use binary for the program or just use hexadecimal/decimal will do?

One more thing, my data sheet does not clearly tell which hexadecimal is for control work. Because without the hexadecimal for the CW, i am not able to program the port using the formula that u gave me.

Read-Only
Author
james yeo
Posted
9-Dec-2008 06:44 GMT
Toolset
C51
New! RE: PCW

wait.... the hexadecimal/name for LED is it P1_0? or is this for the port pin? if this is for the port pin, anyone know where to get control the LED light?

Read-Only
Author
Tamir Michael
Posted
9-Dec-2008 07:10 GMT
Toolset
C51
New! Spaghettization

Please refer to the following resources. They will answer your questions fully. You really cannot expect to make progress without knowing the very based stuff.

Chapter 1
http://www.semiconductors.philips.com/acrobat/various/80C51_FAM_ARCH_1.pdf

chapter 2
http://www.semiconductors.philips.com/acrobat/various/80C51_FAM_PROG_GUIDE_1.pdf

chapter 3
http://www.semiconductors.philips.com/acrobat/various/80C51_FAM_HARDWARE_1.pdf

Read-Only
Author
Andy Neil
Posted
9-Dec-2008 07:57 GMT
Toolset
C51
New! RE: i saw this digram on how control word works.

i saw this digram on how control word works.
Link: http://www.sharpmz.org/mz-700/8255ovview.htm

That link refers to an 8255 chip.

You have never mentioned before that you are using an 8255 chip.

How is anyone supposed to guess what chips you might be using if you don't say?

If you want to use an 8255 chip then, in addition to studying the 8051 and how to use it, you are also going to have to spend time studying the 8255 chip and how to use it.

It seems that you haven't even mastered the basics of the 8051 yet - so you really shouldn't be messing about with the added complications of an 8255 at this point!

Again, the basics for the 8051 are in the so-called "bible":

Chapter 1 - 80C51 Family Architecture:
http://www.nxp.com/acrobat_download/various/80C51_FAM_ARCH_1.pdf

Chapter 2 - 80C51 Family Programmer's Guide and Instruction Set:
http://www.nxp.com/acrobat_download/various/80C51_FAM_PROG_GUIDE_1.pdf

Chapter 3 - 80C51 Family Hardware Description:
http://www.nxp.com/acrobat_download/various/80C51_FAM_HARDWARE_1.pdf

For a tutorial on the basics of the 8051 - including how the ports work - see: http://www.8052.com/tutorial.phtml

There is a whole section about 8051 port IO at http://www.8052.com/faqs - in particular, see: http://www.8052.com/faqs/120176

And, of course, the book lists:
http://www.keil.com/books/8051books.asp
http://www.8052.com/books.phtml

Read-Only
Author
erik malund
Posted
9-Dec-2008 11:43 GMT
Toolset
C51
New! not for beginners

That link refers to an 8255 chip.
not for beginners (and not for advanced either, unless you are an anachronism)
In the olden days the 8255 had its merits; however today all uCs outrun the 8255 and, in addition to the crummy interface, you will get timing problems.

Of course, you 'can' use a 2MHz crystal or such, but what's the point?

Erik

Read-Only
Author
james yeo
Posted
9-Dec-2008 12:54 GMT
Toolset
C51
New! RE: i saw this digram on how control word works.

oo ok cause i heard from my teacher that it need to use control word to program the port whether the port should be input or output. guys thanks alot, i will go read up on the links that you have given me. realli thx alot:)

Read-Only
Author
james yeo
Posted
11-Dec-2008 06:33 GMT
Toolset
C51
New! integrate with RFID

I have another question, how do I pass value from RFID to microcontroller? Do i need to use another port from microcontroller and connect it to RFID? or both RFID and microcontroller connect to the same computer?

Read-Only
Author
Per Westermark
Posted
11-Dec-2008 09:12 GMT
Toolset
C51
New! RE: integrate with RFID

Don't you think that your question requires a description of what type of interface the RFID has, and exactly how you have connected it?

Read-Only
Author
Andy Neil
Posted
11-Dec-2008 09:48 GMT
Toolset
C51
New! How do you want to connect it?

"Do i need to use another port from microcontroller and connect it to RFID?"

If you want to connect the RFID directly to the microcontroller then yes; of course you will need to use some sort of "port" on the microcontroller - exactly what sort of a port will, of course, depend upon what your particular RFID requires!

"or both RFID and microcontroller connect to the same computer?"

If that's what you want then yes; you can do that!

It's your project - only you know the details of what's actually required.

Read-Only
Author
Andy Neil
Posted
11-Dec-2008 09:55 GMT
Toolset
C51
New! Don't try to run before you're even crawling

"I have another question..."

Before moving on to another question, have you actually got the LED working yet?

Blinking an LED really is the most basic, foundational thing to do with a microcontroller - if you can't get that working, you are not ready to move on to anything else!

Next Thread | Thread List | Previous Thread Start a Thread | Settings