in this code Says that nop() make delay for hardware

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#include <intrins.h>

void test_nop (void) {
  P1 = 0xFF;

  _nop_ (); /* delay for hardware */
  _nop_ ();
  _nop_ ();

  P1 = 0x00;
}

 

how i can do this function by codevisionavr ? is it possible? 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What does the CodeVision documentation tell you ... ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What is the source of this code?

 

My guess is it sets a port bit (p1 = 0xFF;)

then delay's using nop's.

then clears a port bit (p1=0;)

 

An oscilloscope or logic analyzer connected to that port pin would show a short blip. 

 

A similar function in any c compiler should be trivial if you know your target cpu and compiler.

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

karimi4511 wrote:
#include <intrins.h>

ki0bk wrote:
know your target cpu and compiler.

Looks like 8051 and Keil C51 ...

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In CV, you would use inline assembler.  (if you investigate intrins.h you will also probably find macros for inline assembler)

 

A single-line inline assembler in CV is explained in the documentation. Example of use:

 

			for (looper = 0; looper < ADC_CHANNELS; looper++)
				{
				#asm("cli");
				adc_total[looper] += adc_raw[looper];
				#asm("sei");
				}

In your case you would probably want #asm("nop");

 

If you care to, you could wrap that in a #define called _nop_ or whatever you like.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What is the source of this code?

 

http://www.keil.com/support/man/...

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
Looks like 8051 and Keil C51 ...
   +1

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i want to work with atmega32 and codevision error while running this code 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

karimi4511 wrote:
error while running this code 

I presume you mean that you get errors when you build this code?

 

This is bound to be the case - because the code is for an entirely different type of chip (an 8051, not an AVR), and relies upon the proprietary extensions of an entirely different compiler (Keil, not CodeVision)!!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

karimi4511 wrote:
i want to work with atmega32 and codevision error while running this code 
Why do you think some code for 8051 is in any way relevant to the AVR? As other have said there are ways to put ASm opcodes in C in Codevision: #asm("NOP") or whatever but maybe an 8051 needs NOPs in some places where nothing in the AVR hardware actually does. So it seems like a very "low level" thing to be trying to port. I would look at the higher level view of things and see if the complete job you are trying to achieve in AVR code is in any way similar to the equivalent 8051 code (seems unlikely).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Why do you think some code for 8051 is in any way relevant to the AVR? 

Maybe this explains why the OP did not seem to grasp your point (repeated by others) in his/her other thread about reading make & model from a chip ...

 

EDIT

 

Link: https://www.avrfreaks.net/comment...

 

 

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Thu. Dec 14, 2017 - 03:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

karimi4511 wrote:

#include <intrins.h>

void test_nop (void) {
  P1 = 0xFF;

  _nop_ (); /* delay for hardware */
  _nop_ ();
  _nop_ ();

  P1 = 0x00;
}

 

how i can do this function by codevisionavr ? is it possible? 


Another way to do this, without NOPs, would be

 

P1 = 0xFF;
P1 = 0xFF;  /* repeat for as long as you want the pulse hi */
P1 = 0xFF;  /* assuming P1 declared 'volatile', these won't be optimized out */
P1 = 0x00;

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What if P1 in an 8051 is like PINB in a Mega 328? ;-) 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

clawson wrote:

What if P1 in an 8051 is like PINB in a Mega 328? ;-) 


Then OP will come to understand why anybody working with uCs needs a scope. :)