AVR a C premenna definovana v bloku

Zuffa Jan ZuffaJ na cgc.sk
Pátek Únor 13 13:02:12 CET 2015


Zeby takto:

while(1){
        uint16_t tmp_counter;
        tmp_counter = 2048;
...

j.


From: Hw-list [mailto:hw-list-bounces na list.hw.cz] On Behalf Of Michal Lukac
Sent: Friday, February 13, 2015 12:55 PM
To: hw-list na list.hw.cz
Subject: AVR a C premenna definovana v bloku

Zdravim, mam takuto cast kodu:
Tu premennu tmp_counter som chcel definovat vnutri toho bloku s tim ze bude platna len v tom bloku a
na zaciatku sa inicializuje, kvoli setreniu miesta v pamati. Lenze to nefunguje prelozi sa to viz. nizsie, ako keby sa ta hodnota nemenila cize to vsetko potom kompilator ignoruje
Ked tu definiciu dam pred to while tak to funguje. chcel som len aby zbytocne nezaberala miesto. Dalo by sa to aj s cyklom for v tomto pripade, ale ma zaujima ked by tam malo byt while
Da sa to nejak inak urobit?

dik.
michal

uint32_t tmp32 = 0;
uint16_t tmp16;

while(1){
        uint16_t tmp_counter = 2048;
        if (bit_is_clear(ADCSRA,ADSC)) {
            tmp16 = ADCL;
            tmp16 |= ((uint16_t)ADCH << 8);
            tmp32 += tmp16;
            tmp_counter--;
            AD_START;
            if (tmp_counter == 0) {
                tmp32 >>= 5;
                offset_I = tmp32;

                utoa((unsigned int)tmp32,s_out,10);
                lcd_gotoxy(0,0);
                lcd_puts(s_out);
                _delay_ms(3000);
                lcd_clrscr();
                break;
            }
        }




   245:         if (bit_is_clear(ADCSRA,ADSC)) {
0000015E  SBIC 0x06,6        Skip if bit in I/O register cleared
0000015F  RJMP PC-0x0001        Relative jump
   246:             tmp16 = ADCL;
00000160  IN R24,0x04        In from I/O location
   247:             tmp16 |= ((uint16_t)ADCH << 8);
00000161  IN R24,0x05        In from I/O location
   250:             AD_START;
00000162  SBI 0x06,6        Set bit in I/O register
00000163  RJMP PC-0x0005        Relative jump
------------- další část ---------------
HTML příloha byla odstraněna...
URL: <http://list.hw.cz/pipermail/hw-list/attachments/20150213/f8e1ec41/attachment.html>


Další informace o konferenci Hw-list