w sumie to ten temat raczej taka akademicka dywagacja na temat przerwań timera. Poniżej dwa podejścia do tematu timera.
1. podejście uważam za niezbyt wygodne, bo zajmuję (marnuję) cały timer 16bit na coraz bardziej rozbudowany podprogram w przerwaniu?
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $regfile = "xm32e5def.dat"
- $crystal = 32000000 '32MHz
- $hwstack = 80
- $swstack = 60
- $framesize = 60
- $lib "lcd_i2c_PCF8574.Lib"
- Config Osc =enabled , 32mhzosc = Enabled
- Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1
- Config Priority = Static , Vector = Application , Lo = Enabled 'Init Interrupts
- dim twi_start as byte
- dim 1sek as long:1sek=0
- dim 3sek as long : 3sek=0
- dim temp_time as integer: temp_time=0
- dim temp_mod as integer
- Config Twic=100000
- Config Scl = Portc.1
- Config Sda = Portc.0
- Open "twic" For Binary As #2
- Config I2cdelay = 10
- I2Cinit #2
- const TWI_ADR = TWIC_CTRL
- const TWI_CH = TWIC_MASTER_DATA 'albo TWIC_MASTER_ADDR
- Dim Pcf8574_lcd As Byte : Pcf8574_lcd = &H4E 'PCF8574 slave address. (&H40,&H42,&H44,&H46,&H48,&H4A,&H4C,&H4E)
- Dim Backlight As Byte : Backlight = 1 'LCD backlight control. (0: off, 1: on)
- Config Lcd = 16x2
- config TCC4=NORMAL,PRESCALE=256
- Tcc4_per=62500
- On Tcc4_ovf Tc4_isr 'Setup overflow interrupt of Timer/Counter C0 and name ISR
- Enable Tcc4_ovf , Lo 'Enable overflow interrupt in LOW Priority
- Enable Interrupts
- Initlcd
- do
- loop
- end
- Tc4_isr:
- incr temp_time
- if temp_time=2 then
- temp_time=0
- incr 1sek
- temp_mod=1sek mod 3
- if temp_mod=0 then incr 3sek
- end if
- Tcc4_intflags.0 = 1
- Locate 1 , 1
- Lcd "Czas 1sek";1sek
- Locate 2 , 1
- Lcd "Czas 3sek";3sek
- Return
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $regfile = "xm32e5def.dat"
- $crystal = 32000000 '32MHz
- $hwstack = 80
- $swstack = 60
- $framesize = 60
- '$lib "xmega.lib" : $external _xmegafix_clear : $external _xmegafix_rol_r1014
- $lib "lcd_i2c_PCF8574.Lib"
- Config Osc =enabled , 32mhzosc = Enabled
- Config Sysclock = 32mhz , Prescalea = 1 , Prescalebc = 1_1
- Config Priority = Static , Vector = Application , Lo = Enabled 'Init Interrupts
- dim twi_start as byte
- dim 1sek as long:1sek=0
- dim 3sek as long : 3sek=0
- dim temp_timea as integer: temp_timea=0
- dim temp_timeb as integer: temp_timeb=0
- Config Twic=100000
- Config Scl = Portc.1
- Config Sda = Portc.0
- Open "twic" For Binary As #2
- Config I2cdelay = 10
- I2Cinit #2
- const TWI_ADR = TWIC_CTRL
- const TWI_CH = TWIC_MASTER_DATA 'albo TWIC_MASTER_ADDR
- Dim Pcf8574_lcd As Byte : Pcf8574_lcd = &H4E 'PCF8574 slave address. (&H40,&H42,&H44,&H46,&H48,&H4A,&H4C,&H4E)
- Dim Backlight As Byte : Backlight = 1 'LCD backlight control. (0: off, 1: on)
- Config Lcd = 16x2
- config TCC4=NORMAL,PRESCALE=256
- Tcc4_CCA=62500
- Tcc4_CCB=62500
- On TCC4_CCA tc4a_isr
- on TCC4_CCB tc4b_isr
- Enable Tcc4_cca , Lo
- Enable Tcc4_ccB , Lo
- Enable Interrupts
- Initlcd
- do
- loop
- end
- Tc4a_isr:
- incr temp_timea
- if temp_timea=2 then
- temp_timea=0
- incr 1sek
- end if
- Locate 1 , 1
- Lcd "Czas 1sek";1sek
- Return
- Tc4b_isr:
- incr temp_timeb
- if temp_timeb=6 then
- temp_timeb=0
- incr 3sek
- end if
- Locate 2 , 1
- Lcd "Czas 3sek";3sek
- Return
Z poważaniem,
Marcin
PS.
Jest power w xmegach..