Show me your code then I can say whether it´s correct.Tell me if this is correct. Thanks
I am not close to that point. I just read the datasheet and look at the initial value of all the registers, they are all disable. Even the Stack Pointer default to the bottom of the SRAM and the Interrupt Vector default to the top of the program memory. It's all set up to just play with it.Show me your code then I can say whether it´s correct.
From your textual description I see nothing wrong.
Klaus
;hello.S
; turns on an LED which is connected to PB5 (digital out 13)
; manual definitions -- later it can include a header file
#define PORTB 0x05
#define DDRB 0x04
#define PB5 5
#define RAMEND 0x8FF
#define SPL 0x3D
#define SPH 0x3E
; local definitions
#define LED_PIN (1<<PB5)
#define DELAY_REGISTER R23
.global main
main:
; initialize stack -- recomended!
;ldi r16,lo8(RAMEND) ; load low byte of RAMEND into r16
;out SPL,r16 ; store r16 in stack pointer low
;ldi r16,hi8(RAMEND) ; load high byte of RAMEND into r16
;out SPH,r16
; setup
ldi R16,LED_PIN
out DDRB,R16
; main loop
Start:
clr R16
out PORTB,R16
ldi DELAY_REGISTER, 50
rcall delay10ms
ldi R16,LED_PIN
out PORTB,R16
ldi DELAY_REGISTER, 50
rcall delay10ms
rjmp Start
#define DELAY_VALUE 39998
delay10ms:
ldi R24,lo8(DELAY_VALUE) ; intialize inner loop count in inner
ldi R25,hi8(DELAY_VALUE) ; loop high and low registers
iLoop: sbiw R24,1 ; decrement inner loop registers (as word:16bits)
brne iLoop ; branch to iLoop if iLoop registers != 0
dec DELAY_REGISTER ; decrement outer loop register
brne delay10ms
ret
avr-gcc -x assembler-with-cpp -Os -Wall hello.S -o hello.o
avr-gcc hello.o -nostartfiles -o hello.elf
avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock hello.elf hello.hex
:1000000000E204B9002705B972E305D000E205B9A2
:1000100072E301D0F7CF8EE39CE90197F1F77A956F
:04002000D1F7089577
:00000001FF
avrdude -Cavrdude.conf -v -patmega328p -carduino -PCOM13 -b9600 -D -Uflash:w:hello.hex:i
avr-gcc -mmcu=atmega328 -x assembler-with-cpp -Os -Wall hello.S -o hello.o
avr-gcc -mmcu=atmega328 hello.o -nostartfiles -o hello.elf
avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock hello.elf hello.hex
:100000000C9434000C943E000C943E000C943E0082
:100010000C943E000C943E000C943E000C943E0068
:100020000C943E000C943E000C943E000C943E0058
:100030000C943E000C943E000C943E000C943E0048
:100040000C943E000C943E000C943E000C943E0038
:100050000C943E000C943E000C943E000C943E0028
:100060000C943E000C943E0011241FBECFEFD8E04C
:10007000DEBFCDBF0E9440000C9452000C940000E3
:1000800000E204B9002705B972E305D000E205B922
:1000900072E301D0F7CF8EE39CE90197F1F77A95EF
:0800A000D1F70895F894FFCF99
:00000001FF
#include <avr/io.h>
#include <util/delay.h>
#define LED_PIN (1<<PB5)
int main(void) {
DDRB = LED_PIN;
while(1) {
PORTB = 0;
_delay_ms(500);
PORTB = LED_PIN;
_delay_ms(500);
}
}
avr-gcc -mmcu=atmega328 -DF_CPU=16000000 -Os -Wall hello.c -o hello.o
avr-gcc -mmcu=atmega328 -DF_CPU=16000000 hello.o -nostartfiles -o hello.elf
avr-objcopy -O ihex -R .eeprom -R .fuse -R .lock hello.elf hello.hex
:100000000C9434000C943E000C943E000C943E0082
:100010000C943E000C943E000C943E000C943E0068
:100020000C943E000C943E000C943E000C943E0058
:100030000C943E000C943E000C943E000C943E0048
:100040000C943E000C943E000C943E000C943E0038
:100050000C943E000C943E000C943E000C943E0028
:100060000C943E000C943E0011241FBECFEFD8E04C
:10007000DEBFCDBF0E9440000C9457000C940000DE
:1000800080E284B915B82FEF39E698E1215030406D
:100090009040E1F700C0000085B92FEF39E698E104
:1000A000215030409040E1F700C00000EBCFF894C1
:0200B000FFCF80
:00000001FF
Thanks for the advice. I am almost done, 3/4 way through.Hi,
I just want to repeat what I and others already told:
No one wants you to read and understand the whole datasheet. I could not do this. I´m the person for "learning by doing". It would take me 10 times longer to learn by reading. An overview is important just to have a clue about the features. But the detailes I learn when I need them.
For sure you are free to go your own. way. Every person is different.
Btw: good job of Kurenai_ryu
Klaus
Do it the way that is the best for you:Part of me tell me I should just play with the kit I have and see, part of me that is curious to go to assembly. Still fighting within me!!
I am the kind that read and design by theory before commit into it. Hardware is not as easy to experiment. I studied RF, doing all the Smith Chart and simulation before I put in circuit. I verified with network analyzer to draw the smith chart and matched very close to the real circuit. Most of my designs were one time through. I spend a lot of time study, analyze before commit. That's my way of doing things.Do it the way that is the best for you:
If you are good in learning from reading papers .. do so.
If you are good in learning form experiments .. do so.
My brother is more the "reading type", I´m more the practical type.
There is not one generally better than the other.
Klaus
#define ledPin 13
// blinks the LED on Arduino UNO pin 13 using a timer1 interrupt
void setup()
{
// pinMode(ledPin, OUTPUT); // C - set LED pin 13 as output
asm("ldi r16,0x20 \n" // DDRB address 0x04 = 0x20 PINB5 output
"out 0x04,r16 \n");
// initialize timer1 -------------------------------------------------
// noInterrupts(); // C - disable all interrupts
asm ("cli \n"); // disable all interrupts
// TCCR1A = 0; // C - clear TCCR1A anf TCCR1B
// TCCR1B = 0;
asm("ldi r16,0x00 \n " // C - clear TCCR1A anf TCCR1B
"sts 0x80,r16 \n" // TCCR1A = 0x80
"sts 0x81,r16 \n"); // TCCR1B = 0x81
// TCNT1 = 34286; // C - preload timer 65536-16MHz/256/2Hz
asm("ldi r17,0x85 \n" // preload timer 65536-16MHz/256/2Hz- Set TCNT1 to 34286 = 0x85EE
"ldi r16,0xEE \n"
"sts 0x85,r17 \n" // TCNT1H = 0x85
"sts 0x84,r16 \n" ); // TCNT1L = 0c84
// TCCR1B |= (1 << CS12); // C - 256 prescaler
asm("ldi r16,004 \n" // 256 prescaler
"sts 0x81,r16 \n" ); // TCCR1B = 0x81
// TIMSK1 |= (1 << TOIE1); // C - enable timer overflow interrupt
asm("ldi r16,0x01 \n" // enable timer overflow interrupt
"sts 0x6F,r16 \n" ); // TIMSK1 = 0x6F
// interrupts(); // C enable all interrupts
asm("sei \n"); // enable interrupts
}
ISR(TIMER1_OVF_vect) // interrupt service routine for Timer 1 overflow
{
// TCNT1 = 34286; // C preload timer
asm("ldi r17,0x85 \n" // preload timer 65536-16MHz/256/2Hz- Set TCNT1 to 34286 = 0x85EE
"ldi r16,0xEE \n"
"sts 0x85,r17 \n" // TCNT1H = 0x85
"sts 0x84,r16 \n"); // TCNT1L = 0x84
// PORTB = (PINB ^ 0x20); // C toggle LED - PORTB = xor (^) of PINB and b00100000- toggle LED
asm("in r24, 0x03 \n" // PINB (0x03) to r24
"ldi r25, 0x20 \n" // b00100000 to r25
"eor r25, r24 \n" // exclusive or r25 and r24
"out 0x05, r25 \n"); // result in r25 to PORTB (0x05)
}
void loop()
{
// your program here...
}
this is a quote .. using the QUOTE button
this is code using the CODE button
Yes. Basically "R23" is a variable (name) with the content "23"You can rename R23 with a different name?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?