Re:How to test code in simulator for atmega88PA

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,I am working on ATmega88PA controller new to atmel Family,i have written the code for 7segment display if i press key1 count has to increased(0,1,2,3,4,5,6,7,8,9) and display on  seven segment display

if i press key2  count has to be decreased from the top.Kindly guide me how i can test this code result in simulator ,where i need to keep breakpoints.Below is the code.

#ifndef F_CPU
#define F_CPU 1000000UL
#endif
#include <avr/io.h>
#include <util/delay.h>
char ssd[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};  //Hexadecimal values for the seven segment display generation
int i=-1;
int main(void)
{

	char flag1=0,flag2=0;  //flags for 2 switches
	DDRD=0XFF;   //enabling the portins PORTA to high
	while(1)
	{
		if(bit_is_clear(PINB,0)&&flag1==0&&i!=9)   //check switch1 is pressed

		{
			++i;                //increase value of i to -1 to 0 for 1st time
			PORTD=ssd[i];      //Assigning segment values to portD
			flag1=1;           //Flag for switch1 is 1 after key press
			
		}

		if(bit_is_set(PINB,0))				//Released condition for switch1
		{
			flag1=0;    //In release condition switch1 flag is zero
		}




		
		if (bit_is_clear(PINB,1)&&flag2==0&&i>0)   //check switch2 is pressed

		{

			--i;             //decreases from the value of present value of increased number
			PORTD=ssd[i];    //Assigning 7segment value to PORTD
			flag2=1;         //For second key press detect making flag2 to be 1
		}
		
		
		if(bit_is_set(PINB,1))			//Released condition for switch2
		{
			if(i<0&&flag2==1)
			{
				

				i=-1;   //after0 if still key pressed detects to not to consider
			}
			flag2=0;    //wen switch not pressed


		}  //end of releasecondition of switch2


	}  //end of while

}  //end of main




















 

Last Edited: Fri. Apr 3, 2015 - 06:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kindly guide me how i can test this code result in simulator

In the project properties set "simulator" as the debugging target then just "start debugging and break". On the toolbar it is the >|| icon. That will load the code into the simulator then break at the entry to main(). You can now place other breakpoints then click the green > icon to start running again.

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

Thank you Clawson for your reply as you told i tried but i am not seeing the value changes in Port D register (for 1= 0x06,2=0x5b,3=0x4f,4=0x66,5=0x6d,6=0x7d,7=0x07,8=0x7f,9=0x6f) so on i am able to see only 0X3F for zero.i need to heck if i press key1 digits to be increament from 0,1,2,3,4, 5,6,7,8,9, if i press key 2 9,8,7,6,5,4,3,2,1.kindly guide me how can i see this values and where i need to keep break points in code.

 

 

Thanks&Regards

Samathasan

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

samathasan wrote:

Thank you Clawson for your reply as you told i tried but i am not seeing the value changes in Port D register (for 1= 0x06,2=0x5b,3=0x4f,4=0x66,5=0x6d,6=0x7d,7=0x07,8=0x7f,9=0x6f) so on i am able to see only 0X3F for zero.i need to heck if i press key1 digits to be increament from 0,1,2,3,4, 5,6,7,8,9, if i press key 2 9,8,7,6,5,4,3,2,1.kindly guide me how can i see this values and where i need to keep break points in code.

 

 

Thanks&Regards

Samathasan

 

I also newer got the hang of this simulator thing. I did not care to ask and just bought the hardware I needed. 

I thought/know I'm a idiot so instead of opening my mouth and remove any doubt about my own stupidity I did not ask here about it.

Apparently it was not all me, so I'm excited about the answer to this.  

screw up in progress 

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

How are you simulating the button being pressed?

 

I myself have always had trouble with the simulator in external inputs.  One way is to create a stimulus file(I have no idea how to do this).

 

THe other, which is what I use, and is clunky is to put a breakpoint at teh instruction that checks the input condition.  Then run the code and let is break at that condition.  Then in the I/O view toggle the bit on the port that corresponds to the button and either single step, or hit run(i prefer single step as you can see what happens)

 

Incidentally, I do not see how you set up the inputs in your code.  Are you using external pullup resistors so the pin sits high - your code looks like is is expecting a logic low condition.

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

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

Also,

Take a look at he following three lines and see if you see what I see....

 

DDRD=0XFF;   //enabling the portins PORTA to high
if(bit_is_clear(PINB,0)&&flag1==0&&i!=9)   //check switch1 is pressed
PORTD=ssd[i];      //Assigning segment values to portD

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user