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
у меня выбили остатки понимания.
где собака зарыта?