roboforum.ru

Технический форум по робототехнике.

Везет мне на баги

Программирование микроконтроллеров AVR, PIC, ARM.
Разработка и изготовление печатных плат для модулей.

Везет мне на баги

Сообщение Fox89 » 06 авг 2008, 20:15

пока часы работают решил попробовать побаловаться с LCD экранчиком, и опять грабли. Везет мне на баги.
CodeVisionAVR 1.25.7 beta 5

Код: Выделить всёРазвернуть
#define DATA_PORT PORTD
#define DATA_PORT_IN PIND
#define DATA_PORT_DDR DDRD
#define RS_PORT PORTC
#define RW_PORT PORTC
#define E_PORT PORTC
#define RS_PIN 0
#define RW_PIN 1
#define E_PIN 2


вот такой код:
Код: Выделить всёРазвернуть
void lcd_init(void)         //init display for 8 bit mode
{
   DATA_PORT = 0;
   //delay_ms(30);
   RS_PORT &= ~(0<<RS_PIN);
   RW_PORT &= ~(0<<RW_PIN);
   DATA_PORT |= 0x30;
   E_PORT |= (1<<E_PIN);
   lcd_wait();
   E_PORT &= ~(0<<E_PIN);
   //delay_ms(10);
   
   RS_PORT &= ~(0<<RS_PIN);
   RW_PORT &= ~(0<<RW_PIN);
   DATA_PORT |= 0x30;
   E_PORT |= (1<<E_PIN);
   lcd_wait();
   E_PORT &= ~(0<<E_PIN);   
   //delay_ms(10);
   
   RS_PORT &= ~(0<<RS_PIN);
   RW_PORT &= ~(0<<RW_PIN);
   DATA_PORT |= 0x30;
   E_PORT |= (1<<E_PIN);
   lcd_wait();
   E_PORT &= ~(0<<E_PIN);
   //delay_ms(1);
   
   RS_PORT &= ~(0<<RS_PIN);      
   RW_PORT &= ~(0<<RW_PIN);
   DATA_PORT = 0x3f;            //N=2 (2 line mode) F=1 (5x11 font)
   E_PORT |= (1<<E_PIN);
   lcd_wait();
   E_PORT &= ~(0<<E_PIN);
   lcd_wait();
   //delay_ms(1);
   
   
   RS_PORT &= ~(0<<RS_PIN);      
   RW_PORT &= ~(0<<RW_PIN);
   DATA_PORT = 0x01;            //display clear
   E_PORT |= (1<<E_PIN);
   lcd_wait();
   E_PORT &= ~(0<<E_PIN);
   lcd_wait();
   //delay_ms(1);
   
   RS_PORT &= ~(0<<RS_PIN);      
   RW_PORT &= ~(0<<RW_PIN);
   DATA_PORT = 0x06;            // I/D=1 (increment mode) SH =0 (entire shift off)
   E_PORT |= (1<<E_PIN);
   lcd_wait();
   E_PORT &= ~(0<<E_PIN);
   lcd_wait();   
   //delay_ms(1); 
   
   putsf("init done ");
   
   return;   
   
};


Ни в протеусе, ни в железе (mega8+winstar WH1602) не работает. Отлаживаю в AVR Studio, он у меня почему то через строчки E_PORT |= (1<<E_PIN); и E_PORT &= ~(0<<E_PIN); просто внаглую проскакивает.
открываю дизасебмлированный код, а там...

Код: Выделить всёРазвернуть
@00000074: lcd_wait
---- sphere__.c -----------------------------------------------------------------------------------
60:          #asm("nop")
+00000074:   0000        NOP                      No operation
61:          #asm("nop")
+00000075:   0000        NOP                      No operation
62:          #asm("nop")
+00000076:   0000        NOP                      No operation
63:          #asm("nop")
+00000077:   0000        NOP                      No operation
64:          return;
+00000078:   9508        RET                      Subroutine return
@00000079: lcd_init
+00000079:   E0E0        LDI     R30,0x00         Load immediate
+0000007A:   BBE2        OUT     0x12,R30         Out to I/O location
71:          RS_PORT &= ~(0<<RS_PIN);
+0000007B:   D0B1        RCALL   PC+0x00B2        Relative call subroutine
72:          RW_PORT &= ~(0<<RW_PIN);
+0000007C:   D0B0        RCALL   PC+0x00B1        Relative call subroutine
73:          DATA_PORT |= 0x30;
+0000007D:   D0B2        RCALL   PC+0x00B3        Relative call subroutine
79:          RS_PORT &= ~(0<<RS_PIN);
+0000007E:   D0AE        RCALL   PC+0x00AF        Relative call subroutine
80:          RW_PORT &= ~(0<<RW_PIN);
+0000007F:   D0AD        RCALL   PC+0x00AE        Relative call subroutine
81:          DATA_PORT |= 0x30;
+00000080:   D0AF        RCALL   PC+0x00B0        Relative call subroutine
87:          RS_PORT &= ~(0<<RS_PIN);
+00000081:   D0AB        RCALL   PC+0x00AC        Relative call subroutine
88:          RW_PORT &= ~(0<<RW_PIN);
+00000082:   D0AA        RCALL   PC+0x00AB        Relative call subroutine
89:          DATA_PORT |= 0x30;
+00000083:   D0AC        RCALL   PC+0x00AD        Relative call subroutine
95:          RS_PORT &= ~(0<<RS_PIN);
+00000084:   D0A8        RCALL   PC+0x00A9        Relative call subroutine
96:          RW_PORT &= ~(0<<RW_PIN);
+00000085:   D0A7        RCALL   PC+0x00A8        Relative call subroutine
97:          DATA_PORT = 0x3f;            //N=2 (2 line mode) F=1 (5x11 font)
+00000086:   E3EF        LDI     R30,0x3F         Load immediate
+00000087:   D0AE        RCALL   PC+0x00AF        Relative call subroutine
101:         lcd_wait();
+00000088:   DFEB        RCALL   PC-0x0014        Relative call subroutine
105:         RS_PORT &= ~(0<<RS_PIN);
+00000089:   D0A3        RCALL   PC+0x00A4        Relative call subroutine
106:         RW_PORT &= ~(0<<RW_PIN);
+0000008A:   D0A2        RCALL   PC+0x00A3        Relative call subroutine
107:         DATA_PORT = 0x01;            //display clear
+0000008B:   E0E1        LDI     R30,0x01         Load immediate
+0000008C:   D0A9        RCALL   PC+0x00AA        Relative call subroutine
111:         lcd_wait();
+0000008D:   DFE6        RCALL   PC-0x0019        Relative call subroutine
114:         RS_PORT &= ~(0<<RS_PIN);
+0000008E:   D09E        RCALL   PC+0x009F        Relative call subroutine
115:         RW_PORT &= ~(0<<RW_PIN);
+0000008F:   D09D        RCALL   PC+0x009E        Relative call subroutine
116:         DATA_PORT = 0x06;            // I/D=1 (increment mode) SH =0 (entire shift off)
+00000090:   E0E6        LDI     R30,0x06         Load immediate
+00000091:   D0A4        RCALL   PC+0x00A5        Relative call subroutine
120:         lcd_wait();
+00000092:   DFE1        RCALL   PC-0x001E        Relative call subroutine
123:         putsf("init done ");
+00000093:   E3EA        LDI     R30,0x3A         Load immediate
+00000094:   E0F0        LDI     R31,0x00         Load immediate
+00000095:   D0A4        RCALL   PC+0x00A5        Relative call subroutine
125:         return;
+00000096:   9508        RET                      Subroutine return

...

--- No Source ------------------------------------------------------------------------------------
+0000010F:   9B5F        SBIS    0x0B,7           Skip if bit in I/O register set
+00000110:   CFFE        RJMP    PC-0x0001        Relative jump
+00000111:   B1EC        IN      R30,0x0C         In from I/O location
+00000112:   9508        RET                      Subroutine return
+00000113:   9B5D        SBIS    0x0B,5           Skip if bit in I/O register set
+00000114:   CFFE        RJMP    PC-0x0001        Relative jump
+00000115:   81E8        LDD     R30,Y+0          Load indirect with displacement
+00000116:   B9EC        OUT     0x0C,R30         Out to I/O location
+00000117:   9621        ADIW    R28,0x01         Add immediate to word
+00000118:   9508        RET                      Subroutine return
+00000119:   931A        ST      -Y,R17           Store indirect and predecrement
+0000011A:   81E9        LDD     R30,Y+1          Load indirect with displacement
+0000011B:   81FA        LDD     R31,Y+2          Load indirect with displacement
+0000011C:   9631        ADIW    R30,0x01         Add immediate to word
+0000011D:   83E9        STD     Y+1,R30          Store indirect with displacement
+0000011E:   83FA        STD     Y+2,R31          Store indirect with displacement
+0000011F:   9731        SBIW    R30,0x01         Subtract immediate from word
+00000120:   91E4        LPM     R30,Z            Load program memory
+00000121:   2F1E        MOV     R17,R30          Copy register
+00000122:   30E0        CPI     R30,0x00         Compare with immediate
+00000123:   F019        BREQ    PC+0x04          Branch if equal
+00000124:   931A        ST      -Y,R17           Store indirect and predecrement
+00000125:   DFED        RCALL   PC-0x0012        Relative call subroutine
+00000126:   CFF3        RJMP    PC-0x000C        Relative jump
+00000127:   E0EA        LDI     R30,0x0A         Load immediate
+00000128:   93EA        ST      -Y,R30           Store indirect and predecrement
+00000129:   DFE9        RCALL   PC-0x0016        Relative call subroutine
+0000012A:   8118        LDD     R17,Y+0          Load indirect with displacement
+0000012B:   9623        ADIW    R28,0x03         Add immediate to word
+0000012C:   9508        RET                      Subroutine return
+0000012D:   B3E5        IN      R30,0x15         In from I/O location
+0000012E:   BBE5        OUT     0x15,R30         Out to I/O location
+0000012F:   9508        RET                      Subroutine return
+00000130:   B3E2        IN      R30,0x12         In from I/O location
+00000131:   63E0        ORI     R30,0x30         Logical OR with immediate
+00000132:   BBE2        OUT     0x12,R30         Out to I/O location
+00000133:   9AAA        SBI     0x15,2           Set bit in I/O register
+00000134:   DF3F        RCALL   PC-0x00C0        Relative call subroutine
+00000135:   CFF7        RJMP    PC-0x0008        Relative jump
+00000136:   BBE2        OUT     0x12,R30         Out to I/O location
+00000137:   9AAA        SBI     0x15,2           Set bit in I/O register
+00000138:   DF3B        RCALL   PC-0x00C4        Relative call subroutine
+00000139:   CFF3        RJMP    PC-0x000C        Relative jump
+0000013A:   93FA        ST      -Y,R31           Store indirect and predecrement
+0000013B:   93EA        ST      -Y,R30           Store indirect and predecrement
+0000013C:   CFDC        RJMP    PC-0x0023        Relative jump
+0000013D:   9AAA        SBI     0x15,2           Set bit in I/O register
+0000013E:   CF35        RJMP    PC-0x00CA        Relative jump
+0000013F:   93EA        ST      -Y,R30           Store indirect and predecrement
+00000140:   CF71        RJMP    PC-0x008E        Relative jump
+00000141:   E6EC        LDI     R30,0x6C         Load immediate
+00000142:   CFFC        RJMP    PC-0x0003        Relative jump
+00000143:   935A        ST      -Y,R21           Store indirect and predecrement
+00000144:   934A        ST      -Y,R20           Store indirect and predecrement
+00000145:   933A        ST      -Y,R19           Store indirect and predecrement
+00000146:   932A        ST      -Y,R18           Store indirect and predecrement
+00000147:   931A        ST      -Y,R17           Store indirect and predecrement
+00000148:   930A        ST      -Y,R16           Store indirect and predecrement
+00000149:   9508        RET                      Subroutine return
+0000014A:   815D        LDD     R21,Y+5          Load indirect with displacement
+0000014B:   814C        LDD     R20,Y+4          Load indirect with displacement
+0000014C:   813B        LDD     R19,Y+3          Load indirect with displacement
+0000014D:   812A        LDD     R18,Y+2          Load indirect with displacement
+0000014E:   8119        LDD     R17,Y+1          Load indirect with displacement
+0000014F:   8108        LDD     R16,Y+0          Load indirect with displacement
+00000150:   9508        RET                      Subroutine return
+00000151:   0000        NOP                      No operation
+00000152:   DFFC        RCALL   PC-0x0003        Relative call subroutine
+00000153:   CFC5        RJMP    PC-0x003A        Relative jump
+00000154:   B3E5        IN      R30,0x15         In from I/O location
+00000155:   BBE5        OUT     0x15,R30         Out to I/O location
+00000156:   9508        RET                      Subroutine return
+00000157:   9AAA        SBI     0x15,2           Set bit in I/O register
+00000158:   CF1B        RJMP    PC-0x00E4        Relative jump
+00000159:   93EA        ST      -Y,R30           Store indirect and predecrement
+0000015A:   CF57        RJMP    PC-0x00A8        Relative jump
+0000015B:   E6EC        LDI     R30,0x6C         Load immediate
+0000015C:   CFFC        RJMP    PC-0x0003        Relative jump
+0000015D:   91E9        LD      R30,Y+           Load indirect and postincrement
+0000015E:   91F9        LD      R31,Y+           Load indirect and postincrement
+0000015F:   9630        ADIW    R30,0x00         Add immediate to word
+00000160:   F039        BREQ    PC+0x08          Branch if equal
+00000161:   ED80        LDI     R24,0xD0         Load immediate
+00000162:   E097        LDI     R25,0x07         Load immediate
+00000163:   9701        SBIW    R24,0x01         Subtract immediate from word
+00000164:   F7F1        BRNE    PC-0x01          Branch if not equal
+00000165:   95A8        WDR                      Watchdog reset
+00000166:   9731        SBIW    R30,0x01         Subtract immediate from word
+00000167:   F7C9        BRNE    PC-0x06          Branch if not equal
+00000168:   9508        RET                      Subroutine return
+00000169:   935A        ST      -Y,R21           Store indirect and predecrement
+0000016A:   934A        ST      -Y,R20           Store indirect and predecrement
+0000016B:   933A        ST      -Y,R19           Store indirect and predecrement
+0000016C:   932A        ST      -Y,R18           Store indirect and predecrement
+0000016D:   931A        ST      -Y,R17           Store indirect and predecrement
+0000016E:   930A        ST      -Y,R16           Store indirect and predecrement
+0000016F:   9508        RET                      Subroutine return
+00000170:   815D        LDD     R21,Y+5          Load indirect with displacement
+00000171:   814C        LDD     R20,Y+4          Load indirect with displacement
+00000172:   813B        LDD     R19,Y+3          Load indirect with displacement
+00000173:   812A        LDD     R18,Y+2          Load indirect with displacement
+00000174:   8119        LDD     R17,Y+1          Load indirect with displacement
+00000175:   8108        LDD     R16,Y+0          Load indirect with displacement
+00000176:   9508        RET                      Subroutine return
+00000177:   0000        NOP                      No operation



особенно то, что строка
Код: Выделить всёРазвернуть
79:          RS_PORT &= ~(0<<RS_PIN);

превращается в

Код: Выделить всёРазвернуть
+0000007E:   D0AE        RCALL   PC+0x00AF        Relative call subroutine

+0000012D:   B3E5        IN      R30,0x15         In from I/O location
+0000012E:   BBE5        OUT     0x15,R30         Out to I/O location
+0000012F:   9508        RET                      Subroutine return

у меня выбили остатки понимания.

где собака зарыта?
Fox89
 
Сообщения: 57
Зарегистрирован: 11 ноя 2007, 20:12
Откуда: урал

Re: Везет мне на баги

Сообщение blindman » 06 авг 2008, 20:29

По дампу лазить неохота, но навскидку

Код: Выделить всёРазвернуть
RS_PORT &= ~(0<<RS_PIN);

Это тоже самое что
Код: Выделить всёРазвернуть
RS_PORT &= ~0;

или
Код: Выделить всёРазвернуть
RS_PORT &= 0xFF;

или
Код: Выделить всёРазвернуть
RS_PORT = RS_PORT;


что мы и видем в ассемблерном коде
Проект [[Open Robotics]] - универсальные модули для построения роботов
Модули Open Robotics можно приобрести в магазине shop.roboforum.ru

Day OFF? You must be pulling my leg! Stop making humor before someone sees you, fool!

Аватара пользователя
blindman
 
Сообщения: 4130
Зарегистрирован: 29 апр 2008, 21:15
Откуда: Хабаровск
прог. языки: C,C++,Assembler,PHP,Javascript,Ruby, SPIN,Java(?)
ФИО: Андрей Юрьевич

Re: Везет мне на баги

Сообщение Fox89 » 06 авг 2008, 21:01

всё равно непонятна причина выкидывания компилятором строк с E_PORT
я уже один раз напарывался что работа с i2c зашита в сам компилятор, и когда я писал свою библиотек мне он выругивался на мои функции зачинающиеся с i2c_init и т.п. пока я не переименовал в fi2c. может есть где то список этих "служебных" слов?
и ни у кого нет случаем прокряканой 2й версии?

Добавлено спустя 18 минут 31 секунду:
скачал 2ю версию CodeVision, переименовал E_PORT в ZE_PORT, E_PIN в ZE_PIN. всё равно, при компиляции все строки с E_PORT выкидываются нафиг(
Fox89
 
Сообщения: 57
Зарегистрирован: 11 ноя 2007, 20:12
Откуда: урал

Re: Везет мне на баги

Сообщение blindman » 06 авг 2008, 21:03

Fox89 писал(а):всё равно непонятна причина выкидывания компилятором строк с E_PORT

Ничего он не выкидывает. Такое поведение - результат оптимизации. Несколько похожих фрагментов кода выносятся в подпрограмму. Так как невозможно одназначно связать адрес в скомпилированном коде с номером строки исходника, то отладочная информация для этих участков кода отсутствует. Если пошагово исполнишь дизассемблированнный код, сам все увидишь.
Проект [[Open Robotics]] - универсальные модули для построения роботов
Модули Open Robotics можно приобрести в магазине shop.roboforum.ru

Day OFF? You must be pulling my leg! Stop making humor before someone sees you, fool!

Аватара пользователя
blindman
 
Сообщения: 4130
Зарегистрирован: 29 апр 2008, 21:15
Откуда: Хабаровск
прог. языки: C,C++,Assembler,PHP,Javascript,Ruby, SPIN,Java(?)
ФИО: Андрей Юрьевич

Re: Везет мне на баги

Сообщение Fox89 » 06 авг 2008, 21:27

я как раз пошагово выполнял - он их выкидывает. да, RS_PORT &= ~(0<<RS_PIN); он их в подпрограмму сунул, но он хотя бы их вызывает, а строки с E_PORT просто выкинул, там по адресам даже видно, что ничего нет.

причем интересно, что переименовав lcd_init в flcd_finit, та ж ерунда, все строки с ZE_PORT он выкинул, но при этом в функции пониже lcd_clear, всё нормально,
Код: Выделить всёРазвернуть
@00000080: lcd_clear
121:         RS_PORT &= ~(0<<RS_PIN);      
+00000080:   D093        RCALL   PC+0x0094        Relative call subroutine
122:         RW_PORT &= ~(0<<RW_PIN);
+00000081:   D092        RCALL   PC+0x0093        Relative call subroutine
123:         DATA_PORT = 0x01;                     
+00000082:   E0E1        LDI     R30,0x01         Load immediate
+00000083:   D099        RCALL   PC+0x009A        Relative call subroutine
127:         flcd_wait();
+00000084:   DFD8        RCALL   PC-0x0027        Relative call subroutine
129:         RW_PORT |= (1<<RW_PIN);
+00000085:   9AA9        SBI     0x15,1           Set bit in I/O register
130:         ZE_PORT |= (1<<ZE_PIN);
+00000086:   D09D        RCALL   PC+0x009E        Relative call subroutine
132:         DATA_PORT_DDR &= ~(0<<7); 
+00000087:   B3E1        IN      R30,0x11         In from I/O location
+00000088:   BBE1        OUT     0x11,R30         Out to I/O location
133:         putsf("start wait busy flag ");
+00000089:   E4E3        LDI     R30,0x43         Load immediate
+0000008A:   E0F0        LDI     R31,0x00         Load immediate
+0000008B:   D095        RCALL   PC+0x0096        Relative call subroutine
134:         while (DATA_PORT_IN & (1<<7))
+0000008C:   9B87        SBIS    0x10,7           Skip if bit in I/O register set
+0000008D:   C007        RJMP    PC+0x0008        Relative jump
136:             ZE_PORT &= ~(0<<ZE_PIN);
+0000008E:   D085        RCALL   PC+0x0086        Relative call subroutine
137:            flcd_wait();
+0000008F:   DFCD        RCALL   PC-0x0032        Relative call subroutine
138:            ZE_PORT |= (1<<ZE_PIN);
+00000090:   D093        RCALL   PC+0x0094        Relative call subroutine
140:         putsf("still busy  ");      
+00000091:   E5E9        LDI     R30,0x59         Load immediate
+00000092:   E0F0        LDI     R31,0x00         Load immediate
+00000093:   D08D        RCALL   PC+0x008E        Relative call subroutine
141:         };
+00000094:   CFF7        RJMP    PC-0x0008        Relative jump
142:         ZE_PORT &= ~(0<<ZE_PIN);
+00000095:   D07E        RCALL   PC+0x007F        Relative call subroutine
143:         DATA_PORT_DDR |= (1<<7);   
+00000096:   9A8F        SBI     0x11,7           Set bit in I/O register
144:         putsf("clear done ");
+00000097:   E6E6        LDI     R30,0x66         Load immediate
+00000098:   E0F0        LDI     R31,0x00         Load immediate
+00000099:   D087        RCALL   PC+0x0088        Relative call subroutine
145:         return;
+0000009A:   9508        RET                      Subroutine return
Fox89
 
Сообщения: 57
Зарегистрирован: 11 ноя 2007, 20:12
Откуда: урал

Re: Везет мне на баги

Сообщение blindman » 06 авг 2008, 21:40

Давай уже все исходники и файл с отладочной информацией, который в AVR studio можно запустить.
Проект [[Open Robotics]] - универсальные модули для построения роботов
Модули Open Robotics можно приобрести в магазине shop.roboforum.ru

Day OFF? You must be pulling my leg! Stop making humor before someone sees you, fool!

Аватара пользователя
blindman
 
Сообщения: 4130
Зарегистрирован: 29 апр 2008, 21:15
Откуда: Хабаровск
прог. языки: C,C++,Assembler,PHP,Javascript,Ruby, SPIN,Java(?)
ФИО: Андрей Юрьевич

Re: Везет мне на баги

Сообщение Fox89 » 06 авг 2008, 22:19

тему можно закрыть и отправить в грабли. дурак я.
E_PORT &= ~(0<<E_PIN);
а надо
E_PORT &= ~(1<<E_PIN);
он и выкидывал строку т.к. она ничего не делала. Извиняюсь за шум.
Fox89
 
Сообщения: 57
Зарегистрирован: 11 ноя 2007, 20:12
Откуда: урал

Re: Везет мне на баги

Сообщение blindman » 06 авг 2008, 22:38

Внимательнее надо быть. То же самое написано в первом моем посте

Добавлено спустя 2 минуты 51 секунду:
За исключением того, что строка не выкидывается.
Проект [[Open Robotics]] - универсальные модули для построения роботов
Модули Open Robotics можно приобрести в магазине shop.roboforum.ru

Day OFF? You must be pulling my leg! Stop making humor before someone sees you, fool!

Аватара пользователя
blindman
 
Сообщения: 4130
Зарегистрирован: 29 апр 2008, 21:15
Откуда: Хабаровск
прог. языки: C,C++,Assembler,PHP,Javascript,Ruby, SPIN,Java(?)
ФИО: Андрей Юрьевич


Вернуться в Микроконтроллеры

Кто сейчас на конференции

Сейчас этот форум просматривают: GoGo.Ru [Bot] и гости: 0

cron