Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Avr test circuit and program

Status
Not open for further replies.

steev

New Member
hi this is my first avr project.
for the test purpose i made a small circuit of flashing LED's.
please checkout the schematic and code
is it correct? when i compiled the asm using wavrasm it created HEX file without any error.

**broken link removed**
 

Attachments

  • 1.txt
    807 bytes · Views: 256
Last edited:
What are you tring to do. I see a switch to reset the uC. And LED on a pin.

I see you are using SER reg writing all ones to registers (for your delay and direction of the pins).

What is not working? Can you give some details?
 
i haven't tested it.
as i said iam complete bigginer.i just wana test the micro controller and the programe.so i want to confirm whether it works or not
is some thing wrong in it?
or can u show me some simple circuit(led) to test the micro controller.
thanks
 
steev said:
i haven't tested it.
as i said iam complete bigginer.i just wana test the micro controller and the programe.so i want to confirm whether it works or not
is some thing wrong in it?
or can u show me some simple circuit(led) to test the micro controller.
thanks

You have fallen into the classic trap of AVR.

AVR uses a stack in data memory in which the user must setup properly the stack pointer before using any CALL/RET instruction. Usually this is done very early after reset.

I'll leave you to figure out how to do just that.

Edited: Perhaps it is not a trap afterall as we all initialise SP with processors in the past until PIC comes along with hardware stack and do away the requirement of user initiating the SP.
 
Last edited:
eblc1388 said:
Edited: Perhaps it is not a trap afterall as we all initialise SP with processors in the past until PIC comes along with hardware stack and do away the requirement of user initiating the SP.

I'm confused as well? - what about the 6502 decades ago?, that had a hardware stack - page 1 of memory if I remember correctly?.
 
Maybe I'm not being clear to Steev.

For processors that do not has a dedicated hardware stack(AVR, 8080,Z80, 8051...) one obviously has to initialise the stack pointer to point to some memory location before using subroutine.
 
Steev,

You need to set the stack pointer, the rcalls to your delay, push the program counter on the stack, jump to your delay, when you hit the ret at the bottom of your delay, it pops the return address from the stack address and returns to the address after the rcall.
 
eblc1388 said:
Maybe I'm not being clear to Steev.

For processors that do not has a dedicated hardware stack(AVR, 8080,Z80, 8051...) one obviously has to initialise the stack pointer to point to some memory location before using subroutine.

Right, so it's only that range of (very similar) processors that require it, all the ones I've ever used don't!. I suppose it depends what type of processor you started with way back when? - in my case 6502 followed by 68000.
 
By dedicated hardware stack I meant a stack which user cannot change or move, as in the case of 16F PIC.

I have not used the 6800, 6502 and 68000 but most likely they all has stack pointers which user can change after reset to set the desire starting location of the stack.

The difference is the default SP after MCU reset might work(albeit not the best location) without user doing anything to the stackpointer. I know 8051 works by allocating the SP at 0x1F giving a workable stack but all most all users change it to somewhere else immediately after reset.
 
eblc1388 said:
By dedicated hardware stack I meant a stack which user cannot change or move, as in the case of 16F PIC.

I have not used the 6800, 6502 and 68000 but most likely they all has stack pointers which user can change after reset to set the desire starting location of the stack.

Certainly you can't move the 6502 stack, it's fixed at page 1 and 256 bytes long, can't really remember the 68000?, I didn't do a lot of assembler on it, mostly removing copy protection so you could install the program on hard drive.

While you obviously seem suprised by the PIC's fixed stack?, I'm suprised by the AVR's moveable one!.
 
Go here **broken link removed**
Search for stack and you will see how to do it. How is that?

Opps, just read the quote, I saw little help and thought you still did not have the stack figured out.

On the programmer. Is it 5VDC? Find a power line and ground, get an LED and a 470 ohm resistor. Drops accross the
power.
 
Last edited:
Wait a minute. All processors give their stack pointers a RESET value. If there is memory there for return addresses to be pushed onto and poped off of then no further initialization is required. On RESET the SP in the 8051 is set to 0x07 and not 0x1F as was stated previously. In this architecture the SP is incremented befor a PUSH and decremented after a POP. The logic is that only one register bank (0x00 to 0x07) is required to get started. If the SP was initialized to 0x1F then the first PUSH would overwrite the first byte of the bit addressable space (0x20 to 0x2F).

As was mentioned, it is often convenient to place the stack at some location besides the RESET value. In my 8051 designs I put the SP at 0xDD for a stack depth of 34 starting at 0xDE, and running through 0xFF.

In the case of the AVR, at least for the AT90CAN128, the initial value of the Stack Pointer is 0x0000. This initial value won't work because the registers are located at address 0x0000. In contrast the ATtiny13 initializes SPL to a value of 0x9F which is the last byte of the internal SRAM, and this will work without further initialization.
 
Last edited:
mramos1 said:
On the programmer. Is it 5VDC? Find a power line and ground, get an LED and a 470 ohm resistor. Drops accross the
power.

i used green-led for this and is working really nice.is it possible to add in process -led too? imean indicator which lights up while burning a chip.

and thanks for the link.its really informative
 
Hi Papabravo,
Papabravo said:
On RESET the SP in the 8051 is set to 0x07 and not 0x1F as was stated previously.

My mistake from quoting from memory as I never use the default SP upon reset.

I cannot find the SP value after reset in the Tiny2313 datasheet, perhaps I'm not looking hard enough.

To Steev & Mramos1,

The reason that there is no power LED and activity LED is simply because the mentioned programmer takes power from the data pin of unused printer data bus to power the AVR. There is not a lot of power available.

Any extra loading, however tiny, could jeopardize the programming operation or make it unreliable. I would remove any LED if I were you.
 
ohh ya right.
programmer exactly need 5volts to work.and any other load might effect the process
thanks man.
 
Oh, no external power supply might be a problem. Might try LED and 2K resistor on power if you are looking an ON LED. I don't think it will hurt the port, chip might not verify after burning worst case.
 
Status
Not open for further replies.

Latest threads

Back
Top