Ребята, кто знает как работае комманда @sleep@ в PicBasic и как контролер пробудить из режима сна по переполнению WDT? так вроде и по даташиту и по логике всё верно, а протеус отказывается пробуждать контроллер (или дело в протеусе?)
Код:
'Written for PICBasic Pro Compiler version 2.50 (www.melabs.com)
'Processor=PIC16F684 (WDT=ON; MCLR=OFF; OSC=INTRC)
DEFINE OSC 8
'*************************************************************
'*************************************************************
'******************** DEFINE CONSTANTS ***********************
'*************************************************************
'*************************************************************
protocol CON 232 '232=MT Core
mtheader CON 2400
mtbit0 CON 600
mtbit1 CON 1200
mtspace CON 600
'*************************************************************
'*************************************************************
'******************** DEFINE VARIABLES ***********************
'*************************************************************
'*************************************************************
bit_counter VAR BYTE
dip_time VAR BYTE
reload_time VAR BYTE
databyte VAR BYTE
databyte1 VAR BYTE
hit_detect VAR BYTE
length VAR BYTE
main_loop_timer VAR WORD
message VAR BYTE
message_ID VAR BYTE
temp VAR BYTE
temp2 VAR BYTE
temp3 VAR WORD
'*************************************************************
'*************************************************************
'******************** PIN ASSIGNMENTS ************************
'*************************************************************
'*************************************************************
Symbol trigger = PORTA.0 'Send Button
Symbol dipsw8 = PORTA.1 'Dip Switch
Symbol dipsw4 = PORTA.2 'Dip Switch
Symbol dipsw2 = PORTA.4 'Dip Switch
Symbol dipsw1 = PORTA.5 'Dip Switch
Symbol statusLED = PORTC.0 'status LED indicator
Symbol mod_out = PORTC.5 'IR mod output / PWM out
'*************************************************************
'*************************************************************
'******************** INITIALIZATION *************************
'*************************************************************
'*************************************************************
initialize:
CLEAR
OSCCON = %01111000
CMCON0 = 7 'turn off comparators
ANSEL = 0
PR2 = 35 'PWM Period (40K=49, 56K=35) (35 to 55)
CCPR1L = 15 'PWM Duty Cycle (1 to 15)
T2CON = 4 'Timer2 = ON; Prescale = 1:1
CCP1CON = 0 'PWM module off
OPTION_REG = %01111111 'Turn PortA weak pull-ups
TRISA = %111111 'set PortA directions
WPUA = %110111 'enable weak pull-ups PortA
IOCA = %000000 'disable PORTA.0 Int On Change
TRISC = %000000 'set PortC directions
PORTA = %000000
PORTC = %000000 '
INPUT trigger
OUTPUT mod_out
OUTPUT statusLED
'---------------------------------------------------------------------------
message_ID = 3
message = $04 'Respawn
IF dipsw1 = 0 THEN
message = $06 'Full Ammo
ENDIF
IF dipsw2 = 0 THEN
dip_time.1 = 1
ENDIF
IF dipsw4 = 0 THEN
dip_time.2 = 1
ENDIF
IF dipsw8 = 0 THEN
dip_time.3 = 1
ENDIF
Lookup dip_time,[1,2,3,4,5,6,9,12],reload_time
'---------------------------------------------------------------------------
'*************************************************************
'*************************************************************
'********************* MAIN PROGRAM **************************
'*************************************************************
'*************************************************************
start:
FOR temp = 1 to reload_time
FOR temp2 = temp to reload_time 'Flash statusLED to indicate Timer Setting
HIGH statusLED '1 Flash = 5 minutes
PAUSE 400
LOW statusLED
PAUSE 250
NEXT temp2
SLEEP 130
NEXT temp
temp3=500
FOR temp = 1 to 50
LOW statusLED
Pause temp3
HIGH statusLED
Pause temp3
temp3 = temp3 - 10
NEXT temp
high statusLED
FOR temp = 1 to 10
GoSub send_message
LOW mod_out
PAUSE 2000
NEXT temp
LOW statusLED
GOTO start
'-----------------------------------------------
'*************************************************************
'*************************************************************
'********************** SUBROUTINES **************************
'*************************************************************
'*************************************************************
send_message: 'send 24 bits
CCP1CON = 12 'send MT header pulse (2.4mS)
pauseus mtheader
CCP1CON = 0
message_first_byte:
databyte = message_ID | %10000000 '(packet_ID=1; sys_msg)
GoSub send_byte
message_second_byte:
databyte = message
GoSub send_byte
message_third_byte:
databyte = protocol
GoSub send_byte
Return
'-----------------------------------------------------------
send_byte: 'send 8 bits (databyte)
For bit_counter = 1 TO 8 'send 8 data bits MSB first
pauseus mtspace 'send space -- space between data pulses
IF databyte.7 = 1 Then trans1
CCP1CON = 12 'send zero
pauseus mtbit0
CCP1CON = 0
@ rlf _databyte,F
GoTo bypassx
trans1:
CCP1CON = 12 'send one
pauseus mtbit1
CCP1CON = 0
@ rlf _databyte,F
bypassx:
Next bit_counter
Return
'-----------------------------------------------------------
send_byte_short: 'send 6 bits (databyte)
For bit_counter = 1 TO 6 'send 6 data bits MSB first
pauseus mtspace 'send space
IF databyte.5 = 1 Then trans1_short 'read from bit 5
CCP1CON = 12 'send zero
pauseus mtbit0
CCP1CON = 0
@ rlf _databyte,F 'databyte << 1
GoTo bypassx_short
trans1_short:
CCP1CON = 12 'send one
pauseus mtbit1
CCP1CON = 0
@ rlf _databyte,F
bypassx_short:
Next bit_counter
Return
'******************************************************
End