martintorres
- 22nd May 2014, 04:13
I'm playing with and I XSCADA problem arose when finished ... program it does not work ... Usually use software-controlled communication, but in this case, as I wanted to meet other microcontroller functions, preferably do control communication hardware ... It's where I start my problem that did not work and I read several topics and I could not take it forward to the project ....
We split.
This is the program I wrote for a PIC16F877A
include "modedefs.bas"
define osc 4
ADCON1=000010
TRISA=255
TRISB=111111
TRISC=000000
OPTION_REG.7=0
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h ;"BRGH a 0 para 2400,-->20, para 9600 ponerlo a 24
DEFINE HSER_BAUD 9600 ;"Velocidad de transmision 9600
DEFINE LCD_DREG PORTD ;bit de datos del LCD empezando
DEFINE LCD_BITS 4 ;en modo 4 bits
DEFINE LCD_DBIT 4 ;por D.4, D.5, D.6 y D.7
DEFINE LCD_RSREG PORTD ;bit de registro del LCD conectar
DEFINE LCD_RSBIT 2 ;en el puerto D.2
DEFINE LCD_EREG PORTD;bit de Enable conectar en el
DEFINE LCD_EBIT 3 ;puerto D.3
DEFINE LCD_LINES 2
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
VOLT VAR WORD
MV VAR BYTE
MA VAR BYTE
HVD var word
AMPER var word
LECTURA VAR WORD
AUX_TX var byte ; NO SE USA
AUX_TX1 VAR BYTE ;PWM
AUX_TX2 VAR BYTE ;ADC
AUX_TX3a VAR BYTE ;ENTRADAS DIG
AUX_TX3b VAR BYTE ;ENTRADAS DIG
AUX_TX3c VAR BYTE ;ENTRADAS DIG
AUX_TX3d VAR BYTE ;ENTRADAS DIG
AUX_TX4 VAR BYTE ;SALIDAS DIG
AUX_TX5 VAR BYTE ;ESTADO PWM
AUX_RX var byte ; NO SE USA
AUX_RX1 VAR BYTE ; NO SE USA
AUX_RX2 VAR BYTE ; NO SE USA
AUX_RX3 VAR BYTE ; NO SE USA
AUX_RX4 VAR BYTE ;ORDEN DEL SCADA
tiempo var byte
bandera var byte
x var byte
nivel var byte
PORTD=0
VOLT=0
PAUSE 100
LCDOUT $FE,1
arranque:
;INTCON = 000000 ' Habilita interrupciones
INTCON.7 = 0 'apago interrupciones generales
INTCON.6 = 0 'idem con perifericas
INTCON.5 = 0 'idem con Int de TMR0
ON INTERRUPT GoTo serialin ' Ante interrupcion ir a "serialin"
;PIE1.5 = 1 ' Habilita interrupciones por USART
PIE1 = 110000 'Enable interrupts
nivel = 0
INICIO:
If PIR1.5 = 1 Then Goto serialin
;HSerIn [Dec AUX_RX]
IF portc.4 = 0 THEN gosub sumarPWM1
IF portc.5 = 0 THEN gosub restarPWM1
IF portb.1 = 0 then
AUX_TX3a = 11
else
AUX_TX3a = 10
endif
if portb.2 = 0 then
AUX_TX3b =21
else
AUX_TX3b =20
endif
if portb.3 = 0 then
AUX_TX3c =31
else
AUX_TX3c =30
endif
if portb.4 = 0 then
AUX_TX3d =41
else
AUX_TX3d =40
endif
IF ADCON0.2= 1 THEN INICIO
gosub lectura_ADC
LCDOUT $FE,1
LCDOUT $FE,$02,"V=",DEC VOLT,",",DEC1 MV," A=",DEC2 AMPER,",",DEC2 MA
LCDOUT $FE,$C0,"pwm=",DEC tiempo
AUX_TX5 = NIVEL
AUX_TX4 = PORTD
AUX_TX2 = AMPER
AUX_TX1 = VOLT
PWM PORTC.2,nivel,100
pause 5
HSEROUt ["[1;1;W;",dec AUX_TX1,13] ;envio adc volts
HSEROUt ["1;1;W;",dec AUX_TX1,13] ;envio adc volts
pause 5
HSEROUt ["[","1","1","W",dec AUX_TX1,"]",13] ;envio adc volts
HSEROUt ["[1;2;W;",AUX_TX2,13] ;envio adc amp
pause 5
HSEROUt ["[1;3;W;",AUX_TX3a,13] ;envio estado entradas digitales
pause 5
HSEROUt ["[1;3;W;",AUX_TX3b,13] ;envio estado entradas digitales
pause 5
HSEROUt ["[1;3;W;",AUX_TX3c,13] ;envio estado entradas digitales
pause 5
HSEROUt ["[1;3;W;",AUX_TX3d,13] ;envio estado entradas digitales
pause 5
HSEROUt ["[1;4;W;",AUX_TX4,13] ;envio estado salidas digitales
pause 5
HSEROUt ["[1;5;W;",AUX_TX5,13] ;envio estado PWM
GOTO INICIO
lectura_ADC:
ADCIN 0,LECTURA
HVD=((LECTURA+1)*/875)/10
VOLT=HVD/10
MV=(HVD)//10
ADCIN 1,LECTURA
HVD=(LECTURA+1)*/250
AMPER=HVD/100
MA=HVD//100
return
sumarPWM1:
if nivel => 255 then return
nivel= nivel+5
return
restarPWM1:
if nivel => 1 then return
nivel = nivel - 1
return
DISABLE
serialin: ' Buffer the character received
PIE1 = 000000 'Disable interrupts
HSerIn [Dec AUX_RX, dec AUX_RX1, DEC AUX_RX2 , DEC AUX_RX3]
Select case AUX_RX3
case 1
toggle PORTC.0
case 2
TOGGLE PORTC.2
case 3
TOGGLE PORTC.3
case 4
TOGGLE PORTC.4
case 5
if nivel => 255 then INICIO
nivel= nivel+5
return
CASE 6
if nivel => 1 then INICIO
nivel = nivel - 1
return
END SELECT
PIE1 = 110000 'Enable interrupts
Resume
end
The editor of scada, can handle multiple communication protocols.
Ascii Protokol :
Send String Via RS232
[1;1;W;40] Format : [DeviceAdres;RegAdres;Write;Value]
Receive String Via RS232
[1;1;W;40] Format : [DeviceAdres;RegAdres;Read;Value]
In my case, configure the different entries in different variables (addresses) to control the functions ... For example, to control the analog voltmeter and ammeter, select the Address List 1 and 2 ($ 1 - $ 2) ...
I mean, from the pic would have to send
[1,1, W, adc value Volts] and [1,2, W, Amp adc value].
This same action, but with different addresses can complete them with the various functions of the software, but when run proteus and scada, and does not work in proteus rs-232 terminal, you see the error indicator ...
7350 7351
I help to find the problem that really do not understand?
No if I firewall blocks port ...
not if I am misusing HSERIN and HSEROUT ...
or, is some small error
We split.
This is the program I wrote for a PIC16F877A
include "modedefs.bas"
define osc 4
ADCON1=000010
TRISA=255
TRISB=111111
TRISC=000000
OPTION_REG.7=0
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h ;"BRGH a 0 para 2400,-->20, para 9600 ponerlo a 24
DEFINE HSER_BAUD 9600 ;"Velocidad de transmision 9600
DEFINE LCD_DREG PORTD ;bit de datos del LCD empezando
DEFINE LCD_BITS 4 ;en modo 4 bits
DEFINE LCD_DBIT 4 ;por D.4, D.5, D.6 y D.7
DEFINE LCD_RSREG PORTD ;bit de registro del LCD conectar
DEFINE LCD_RSBIT 2 ;en el puerto D.2
DEFINE LCD_EREG PORTD;bit de Enable conectar en el
DEFINE LCD_EBIT 3 ;puerto D.3
DEFINE LCD_LINES 2
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 50
VOLT VAR WORD
MV VAR BYTE
MA VAR BYTE
HVD var word
AMPER var word
LECTURA VAR WORD
AUX_TX var byte ; NO SE USA
AUX_TX1 VAR BYTE ;PWM
AUX_TX2 VAR BYTE ;ADC
AUX_TX3a VAR BYTE ;ENTRADAS DIG
AUX_TX3b VAR BYTE ;ENTRADAS DIG
AUX_TX3c VAR BYTE ;ENTRADAS DIG
AUX_TX3d VAR BYTE ;ENTRADAS DIG
AUX_TX4 VAR BYTE ;SALIDAS DIG
AUX_TX5 VAR BYTE ;ESTADO PWM
AUX_RX var byte ; NO SE USA
AUX_RX1 VAR BYTE ; NO SE USA
AUX_RX2 VAR BYTE ; NO SE USA
AUX_RX3 VAR BYTE ; NO SE USA
AUX_RX4 VAR BYTE ;ORDEN DEL SCADA
tiempo var byte
bandera var byte
x var byte
nivel var byte
PORTD=0
VOLT=0
PAUSE 100
LCDOUT $FE,1
arranque:
;INTCON = 000000 ' Habilita interrupciones
INTCON.7 = 0 'apago interrupciones generales
INTCON.6 = 0 'idem con perifericas
INTCON.5 = 0 'idem con Int de TMR0
ON INTERRUPT GoTo serialin ' Ante interrupcion ir a "serialin"
;PIE1.5 = 1 ' Habilita interrupciones por USART
PIE1 = 110000 'Enable interrupts
nivel = 0
INICIO:
If PIR1.5 = 1 Then Goto serialin
;HSerIn [Dec AUX_RX]
IF portc.4 = 0 THEN gosub sumarPWM1
IF portc.5 = 0 THEN gosub restarPWM1
IF portb.1 = 0 then
AUX_TX3a = 11
else
AUX_TX3a = 10
endif
if portb.2 = 0 then
AUX_TX3b =21
else
AUX_TX3b =20
endif
if portb.3 = 0 then
AUX_TX3c =31
else
AUX_TX3c =30
endif
if portb.4 = 0 then
AUX_TX3d =41
else
AUX_TX3d =40
endif
IF ADCON0.2= 1 THEN INICIO
gosub lectura_ADC
LCDOUT $FE,1
LCDOUT $FE,$02,"V=",DEC VOLT,",",DEC1 MV," A=",DEC2 AMPER,",",DEC2 MA
LCDOUT $FE,$C0,"pwm=",DEC tiempo
AUX_TX5 = NIVEL
AUX_TX4 = PORTD
AUX_TX2 = AMPER
AUX_TX1 = VOLT
PWM PORTC.2,nivel,100
pause 5
HSEROUt ["[1;1;W;",dec AUX_TX1,13] ;envio adc volts
HSEROUt ["1;1;W;",dec AUX_TX1,13] ;envio adc volts
pause 5
HSEROUt ["[","1","1","W",dec AUX_TX1,"]",13] ;envio adc volts
HSEROUt ["[1;2;W;",AUX_TX2,13] ;envio adc amp
pause 5
HSEROUt ["[1;3;W;",AUX_TX3a,13] ;envio estado entradas digitales
pause 5
HSEROUt ["[1;3;W;",AUX_TX3b,13] ;envio estado entradas digitales
pause 5
HSEROUt ["[1;3;W;",AUX_TX3c,13] ;envio estado entradas digitales
pause 5
HSEROUt ["[1;3;W;",AUX_TX3d,13] ;envio estado entradas digitales
pause 5
HSEROUt ["[1;4;W;",AUX_TX4,13] ;envio estado salidas digitales
pause 5
HSEROUt ["[1;5;W;",AUX_TX5,13] ;envio estado PWM
GOTO INICIO
lectura_ADC:
ADCIN 0,LECTURA
HVD=((LECTURA+1)*/875)/10
VOLT=HVD/10
MV=(HVD)//10
ADCIN 1,LECTURA
HVD=(LECTURA+1)*/250
AMPER=HVD/100
MA=HVD//100
return
sumarPWM1:
if nivel => 255 then return
nivel= nivel+5
return
restarPWM1:
if nivel => 1 then return
nivel = nivel - 1
return
DISABLE
serialin: ' Buffer the character received
PIE1 = 000000 'Disable interrupts
HSerIn [Dec AUX_RX, dec AUX_RX1, DEC AUX_RX2 , DEC AUX_RX3]
Select case AUX_RX3
case 1
toggle PORTC.0
case 2
TOGGLE PORTC.2
case 3
TOGGLE PORTC.3
case 4
TOGGLE PORTC.4
case 5
if nivel => 255 then INICIO
nivel= nivel+5
return
CASE 6
if nivel => 1 then INICIO
nivel = nivel - 1
return
END SELECT
PIE1 = 110000 'Enable interrupts
Resume
end
The editor of scada, can handle multiple communication protocols.
Ascii Protokol :
Send String Via RS232
[1;1;W;40] Format : [DeviceAdres;RegAdres;Write;Value]
Receive String Via RS232
[1;1;W;40] Format : [DeviceAdres;RegAdres;Read;Value]
In my case, configure the different entries in different variables (addresses) to control the functions ... For example, to control the analog voltmeter and ammeter, select the Address List 1 and 2 ($ 1 - $ 2) ...
I mean, from the pic would have to send
[1,1, W, adc value Volts] and [1,2, W, Amp adc value].
This same action, but with different addresses can complete them with the various functions of the software, but when run proteus and scada, and does not work in proteus rs-232 terminal, you see the error indicator ...
7350 7351
I help to find the problem that really do not understand?
No if I firewall blocks port ...
not if I am misusing HSERIN and HSEROUT ...
or, is some small error