Code: Select all
module Rlab_Module
include Rbus_lib
include General_drive_led
'include General_drive_led
'include Rlab_Module
'dim UCSPin as sbit at rf3_bit
' UCSPin_dir as sbit at trisf.3
'const Nled as word = 50
Symbol Pulsante0 = Pulsanti_Ingresso[0]
Symbol Pulsante1 = Pulsanti_Ingresso[1]
Symbol Pulsante2 = Pulsanti_Ingresso[2]
Symbol Pulsante3 = Pulsanti_Ingresso[3]
Symbol pulsante4 = Pulsanti_Ingresso[4]
Symbol Pulsante5 = Pulsanti_Ingresso[5]
symbol GPIO5 = GPIO.5
symbol GPIO4 = GPIO.4
symbol GPIO3 = GPIO.3
symbol GPIO2 = GPIO.2
symbol GPIO1 = GPIO.1
symbol GPIO0 = GPIO.0
const ID_ as byte external
Room as byte external
'dichiarazioni interfaccia 1 ingresso living
Dim GPIO as byte
dim UCSPin as sbit at RB2_bit
UCSPin_dir as sbit at TRISB.2
WS281xPin as sbit at RB2_bit
WS281xPin_dir as sbit at TRISB.2
RbusTx as sbit at RB4_bit
RbusTx_dir as sbit at TRISB.4
RbusRx as sbit at RB5_bit
RbusRx_dir as sbit at TRISB.5
RbusRTx as sbit at RA4_bit
RbusRTx_dir as sbit at trisa.4
led as sbit at RA1_bit
led_dir as sbit at TRISA.1
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
dim Pulsanti_Ingresso as longword[6]
ColorCheck as longword
sub procedure EventUmidita(dim RW as byte)
sub procedure EventTemperature(dim RW as byte)
sub procedure EventInterface(dim RW as byte)
sub procedure EventPWM()
sub procedure EventUCS()
sub procedure EventWS()
sub procedure Interfaccia_Slave_Small_Init()
sub procedure GPort_Write()
sub function GPort_Read() as boolean
implements
const V0 as byte = 0x00
sub procedure RbusInt() iv IVT_CHANGE_NOTICE ilevel 7 ics ICS_SOFT
CNBIF_bit = 0
Rbus_read
RBus_Write(buffer64)
led = not led
end sub
Sub procedure SetCn
anselb.b5 = 0
DisableInterrupts()
cnconb.ON_ = 1
cnconb.SIDL = 0
cnenb.cnieb5 = 1
cnip0_bit = 1
cnip1_bit = 1
cnip2_bit = 1
cnis0_bit = 1
cnis1_bit = 1
cnpub = 1
cnpdb = 0
IFS1.CNBIF = 0
IEC1.CNBIE = 1
EnableInterrupts()
end sub
sub procedure Interfaccia_Slave_Small_Init()
JTAGEN_bit = 0
Pulsanti_Ingresso[0] = 0
Latb = 0xFFC4
Lata.0 = 1
TRISB.15 = 0
TRISB.14 = 0
TRISB.13 = 0
TRISB.12 = 0
TRISB.11 = 0
TRISB.10 = 0
TRISB.9 = 1
TRISB.8 = 1
TRISB.7 = 1
TRISB.6 = 1
TRISB.3 = 1
TRISA.0 = 1
anselb = 0
ansela = 0
led = 0
led_dir = 0
RBus_init
GPIO = 0xff
SetCn
end sub
sub procedure GPort_Write()
RB15_bit = GPIO5
RB14_bit = GPIO4
RB13_bit = GPIO3
RB12_bit = GPIO2
RB11_bit = GPIO1
RB10_bit = GPIO0
end sub
sub function GPort_Read() as boolean
if (PortB.9 = V0) or (PortB.8 = V0) or (PortB.7 = V0) or (PortB.6 = V0) or (PortA.0 = V0) or (PortB.3 = V0) then
if portb.8 = 0 then
GPIO.5 = not GPIO.5
RBus_Write(Rpackage(master, root, Winterface, p6, GPIO, 0x00, 0x00))
end if
if portb.7 = 0 then
GPIO.4 = not GPIO.4
RBus_Write(Rpackage(master, root, Winterface, p5, GPIO, 0x00, 0x00))
end if
if portb.6 = 0 then
GPIO.3 = not GPIO.3
RBus_Write(Rpackage(master, root, Winterface, p4, GPIO, 0x00, 0x00))
end if
if portb.9 = 0 then
GPIO.2 = not GPIO.2
RBus_Write(Rpackage(master, root, Winterface, p3, GPIO, 0x00, 0x00))
end if
if porta.0 = 0 then
GPIO1 = not GPIO.1
RBus_Write(Rpackage(master, root, Winterface, p2, GPIO, 0x00, 0x00))
end if
if portb.3 = 0 then
GPIO.0 = not GPIO.0
RBus_Write(Rpackage(master, root, Winterface, p1, GPIO, 0x00, 0x00))
end if
'led = not led
result = 1
delay_ms(300)
else
result = 0
end if
end sub
sub procedure EventUmidita(dim RW as byte)
end sub
sub procedure EventTemperature(dim RW as byte)
end sub
sub procedure EventInterface(dim RW as byte)
select case buffer.RXTypeID
case p1
GPIO.0 = not GPIO.0
case p2
GPIO.1 = not GPIO.1
case p3
GPIO.2 = not GPIO.2
case p4
GPIO.3 = not GPIO.3
case p5
GPIO.4 = not GPIO.4
case p6
GPIO.5 = not GPIO.5
end select
GPort_Write()
end sub
sub procedure EventPWM()
end sub
sub procedure EventUCS()
select case Buffer.RXTypeID
case 1
Pulsante0 = RGBtoLongWord(Buffer.RXD2, Buffer.RXD1, Buffer.RXD0)
case 2
Pulsante1 = RGBtoLongWord(Buffer.RXD2, Buffer.RXD1, Buffer.RXD0)
case 3
Pulsante2 = RGBtoLongWord(Buffer.RXD2, Buffer.RXD1, Buffer.RXD0)
case 4
Pulsante3 = RGBtoLongWord(Buffer.RXD2, Buffer.RXD1, Buffer.RXD0)
case 5
Pulsante4 = RGBtoLongWord(Buffer.RXD2, Buffer.RXD1, Buffer.RXD0)
case 6
Pulsante5 = RGBtoLongWord(Buffer.RXD2, Buffer.RXD1, Buffer.RXD0)
end select
UcsBufferWrite(Pulsanti_Ingresso)
end sub
sub procedure EventWS()
end sub
end.
Code: Select all
program ISS_test
include Rbus_lib
include Rlab_Module
include General_drive_led
' Declarations section
const ID_ as byte = 0x11
Room_ as byte = living
Nled as byte = 6
dim Gram as longword[Nled]
main:
EI()
EnableInterrupts()
'DisableContextSaving()
'Main program
WS281x_Init
UCS_init
Interfaccia_Slave_Small_Init()
UcsBufferWrite(Pulsanti_Ingresso)
While True
if GPort_Read() = 1 then
' GPO = GPI
GPort_Write()
UcsBufferWrite(Pulsanti_Ingresso)
end if
Event
'led = portb.3
wend
end.
as you can see as long as the interrupt does not trigger the main funfiona very well, while with the advent of the interrupt the process gets stuck, and within the interrupt there are two procedures that are not executed
Code: Select all
sub procedure RBus_Write(dim arr as uint64)
dim a as byte
'RbusRTx = 1
for a = 63 to 0 step - 1
RbusTx = 1
if arr.a = 0 then
delay_us(10)
else
delay_us(20)
end if
RbusTx = 0
if arr.a = 0 then
delay_us(20)
else
delay_us(10)
end if
next a
'RbusRTx = 0
end sub
sub procedure Rbus_Read()
dim a,bb as byte
for a = 63 to 0 step -1
delay_us (11)
if RbusRx = 1 then
Buffer64.a = RbusRx
end if
delay_us(18)
while RbusRx = 0
wend
next a
DataOk = 1
end sub