czytanie stanu pinu w Bascom AVR

Loading thread data ...

Piotr snipped-for-privacy@poczta.onet.pl> napisał(a):

Spróbuj tak: .. Config Pind.4 = Input 'Ustaw jako wejście Portd.4 = 1 'Włącz Pull-up If Pind.4=0 Then ..

Piotr ;)

Reply to
Piotrek Sz.

Piotr napisał(a):

W rejestrze portX można odczytać wartośc którą się wpisało do portu ale do odczytu stanu wejść widzianych z zewnątrz mikrokontrolera trzeba użyć rejestru pinX.X lub odczytu całego portu pinX.

Reply to
zuras

Zamiast czekać na odsiecz wróżki, która zgadnie czemu to nie działa, mógłbyś o wiele szybciej porównać kody wynikowe obydwu przypadków (bascom produkuje jakiś listing assemblerowy?).

Reply to
Zbych

Piotr snipped-for-privacy@poczta.onet.pl> napisał(a):

Postanowiłem częściowo zastąpić wróżkę ;-) Kod jaki wygenerował Bascom: ..

3: Config Pind.4 = Input +00000026: 988C CBI 0x11,4 Clear bit in I/O register 4: Set Portd.4 +00000027: 9A94 SBI 0x12,4 Set bit in I/O register ;--------------------------------------------------------------------- 6: A = Pind.4 +00000028: 27BB CLR R27 Clear Register +00000029: E3A0 LDI R26,0x30 Load immediate 6: A = Pind.4 +0000002A: 918C LD R24,X Load indirect +0000002B: FB84 BST R24,4 Bit store from register to T 6: A = Pind.4 +0000002C: E6A0 LDI R26,0x60 Load immediate +0000002D: E0B0 LDI R27,0x00 Load immediate 6: A = Pind.4 +0000002E: 2788 CLR R24 Clear Register +0000002F: F980 BLD R24,0 Bit load from T to register 6: A = Pind.4 +00000030: 938C ST X,R24 Store indirect ;---------------------------------------------------------------------- 7: If Pind.4 = 0 Then +00000031: 2700 CLR R16 Clear Register +00000032: 27BB CLR R27 Clear Register 7: If Pind.4 = 0 Then +00000033: E3A0 LDI R26,0x30 Load immediate +00000034: 918C LD R24,X Load indirect 7: If Pind.4 = 0 Then +00000035: FB84 BST R24,4 Bit store from register to T +00000036: F40E BRTC PC+0x02 Branch if T flag cleared 7: If Pind.4 = 0 Then +00000037: E001 LDI R16,0x01 Load immediate +00000038: E040 LDI R20,0x00 Load immediate 7: If Pind.4 = 0 Then +00000039: 1704 CP R16,R20 Compare +0000003A: F009 BREQ PC+0x02 Branch if equal 7: If Pind.4 = 0 Then +0000003B: C001 RJMP PC+0x0002 Relative jump 8: nop +0000003C: 0000 NOP No operation 10: Loop +0000003D: CFEA RJMP PC-0x0015 Relative jump +0000003E: 9731 SBIW R30,0x01 Subtract immediate from word 10: Loop +0000003F: F7F1 BRNE PC-0x01 Branch if not equal +00000040: 9508 RET Subroutine return 10: Loop +00000041: 9468 SET Set T in SREG +00000042: F862 BLD R6,2 Bit load from T to register 10: Loop +00000043: 9508 RET Subroutine return +00000044: 94E8 CLT Clear T in SREG 10: Loop +00000045: F862 BLD R6,2 Bit load from T to register +00000046: 9508 RET Subroutine return .. dla poniższego źródła:

$regfile = "m8def.dat" Dim A As Byte Config Pind.4 = Input Set Portd.4 Do A = Pind.4 If Pind.4 = 0 Then nop End If Loop

Jak dla mnie OK , mimo że zrobione jakby okrężną drogą :)

Piotr

PS Pokaż całe źródło , jeśli chcesz ;)

Reply to
Piotrek Sz.

Piotr snipped-for-privacy@poczta.onet.pl> napisał(a):

Na taki luksus , pozwala AvrStudio.Już dawno zarzuciłem bascomowy symulator.

Ani słówkiem nie wspomniałeś , że tylko "symulujesz" ;)

To jest bez znaczenia.Dowolna zmienna , przed zapisem do niej wartości bitowej , jest zerowana.

..

Piotrek

Reply to
Piotrek Sz.

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.