In SX Microcontrollers, SX/B Compiler and SX-Key Tool, smhhadima wrote: Dear Jonny, 1- I'm sorry if my big bold letters was interpreted as SHOUTING I was not trying to shout, I just wanted to make my point clear. (please accept my appology) 2-I removed the SUBs coding to make the text short and easy to read. and because these subs were mostly written by you, I thought there's no need to post the whole code of what you already know. Anyway, here is the whole code: '' ========================================================================= ' ' File...... ' Purpose... ' ========================================================================= ' ------------------------------------------------------------------------- ' Program Description ' ------------------------------------------------------------------------- ' ' ' -- requires SX/B 2.00.16 or later ' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- ID "Master" DEVICE SX28, OSCXT2, BOR22 FREQ 20_000_000 ' ------------------------------------------------------------------------- ' I/O Pins ' ------------------------------------------------------------------------- LcdBus PIN RA ' port to use DB4 PIN LcdBus.0 OUTPUT DB5 PIN LcdBus.1 OUTPUT DB6 PIN LcdBus.2 OUTPUT DB7 PIN LcdBus.3 OUTPUT Lcd_E PIN RC.0 OUTPUT Lcd_RS PIN RC.1 OUTPUT Ser_pin PIN RC.2 INPUT Ser_ctrl PIN RC.3 OUTPUT Dn_limit PIN RB.3 INPUT SCHMITT PULLUP Up_limit PIN RB.4 INPUT SCHMITT PULLUP Maint_swt1 PIN RB.5 INPUT SCHMITT PULLUP INTR_FALL Maint_swt2 PIN RB.6 INPUT SCHMITT PULLUP INTR_FALL NOT_USED PIN RB.7 output NOpullup NOT_USED2 PIN RB.2 output NOpullup ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- Baud CON "N9600" LcdCls CON $01 ' clear the LCD * LcdHome CON $02 ' move cursor home * LcdCrsrL CON $10 ' move cursor left LcdCrsrR CON $14 ' move cursor right LcdLine1 CON $80 ' DDRAM address of line 1 LcdLine2 CON $C0 ' DDRAM address of line 2 ' * LCD needs 2ms delay after these commands CamFail_Cnt CON 5 Int_Req CON 5 Ext_Req CON 4 No_Req CON 2 Full_collective CON 0 UP CON 1 DOWN CON 0 Close CON 0 OFF CON 0 automatic con 1 Light_ON CON "n" Light_off CON "f" Cam_close con "c" Clear_all CON "i" update_que con "u" Cam_open CON "p" fork_time con 1000 'waiting time after fork is closed Cam_trial CON 5 buffer CON 16 ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- QUE VAR byte (buffer) Temp VAR Byte (buffer) password var word tmp VAR Byte ' work vars Cam_time Var byte ' Wating time after Cam-on Stop_time Var byte 'wating time before closing the Cam/door Light_timer var tmp Last_flr var byte 'camfail_cnt VAR byte Slow_timeout var byte fast_timeout var byte Que_cntr VAR Byte Crnt_flr VAR byte collective_opt var bit '0= full collective, 1=Down collective Door_option Var bit '0=normal 1=Automatic dir VAR bit '0=down 1=up light_flag VAr bit '0=light is off 1=lights is on ' ------------------------------------------------------------------------- INTERRUPT ' ------------------------------------------------------------------------- goto ISR_Start ' ========================================================================= ' Subroutine / Function / Task Declarations ' ========================================================================= TX_byte SUB 1,1,Byte RX_byte FUNC 1,1 LCD_INIT SUB 0 ' initialize LCD LCD_BLIP SUB 0 ' blip LCD "E" pin LCD_CMD SUB 1, 1, Byte ' send LCD command LCD_OUT SUB 1, 1, Byte ' print char on LCD LCD_STR SUB 2, 2, Word ' print string on LCD LCD_SET_CRSR SUB 1, 1, Byte ' set cursor mode DELAY_MS SUB 2, 2, Word, Word ' shell for PAUSE DELAY_US SUB 2, 2, Word, Word ' shell for PAUSEUS GET_REQUESTS SUB 1,1,Byte GET_DIR SUB 0 ISR_Start: WKPND_B=tmp ISR_Exit: WKEN_B = %10011110 'enable interrupt @ pin 0,5,6 (fork, Maint1,Maint2) RETURNINT ' ========================================================================= PROGRAM Start ' ========================================================================= Start: tmp=0 do que(tmp)=no_req inc tmp loop until tmp=buffer GET_REQUESTS Int_Req watch tmp Break TX_byte clear_all Lcd_Setup: DELAY_MS 50 ' let LCD self-init LCD_INIT ' initialize (multi-line) LCD_CMD LcdCls DELAY_MS 250 ' for effect Main: rc=rc and %00001111 'STOP (All Relays off) ' LCD_STR "[url=http://www.HadimaTech.com]www.HadimaTech.com[/url]" ' Tmp = LcdLine2 + 2 ' move to position ' LCD_CMD Tmp DELAY_MS Stop_time GET_REQUESTS Int_Req GET_REQUESTS Ext_Req if door_option=automatic then close_automatic: TX_byte cam_close tmp=RX_byte 100 if tmp<>cam_close then close_automatic endif DELAY_MS fork_time tmp=0 TX_byte cam_close DELAY_MS CAM_time if tmp=cam_trial then cam_fail inc tmp GET_REQUESTS Int_Req GET_REQUESTS Ext_Req '-------------------- MOVE2: WKPND_B = %00000000 ' clear pending WKED_B = %00000000 ' rising edge detect WKEN_B = %10011110 'enable interrupt @ pin 0,5,6 (fork, Maint1,Maint2) Moving: tmp=RX_byte fast_timeout 'wait for sensor_1 flag if tmp<>"f" then move_slow if dir=up then inc crnt_flr else dec crnt_flr endif GET_REQUESTS Int_Req GET_REQUESTS Ext_Req if que(crnt_flr)=no_req then Moving if dir=up then if Que(crnt_flr)=ext_req then tmp=crnt_flr 'check if there is an internal request up there do until tmp=last_flr inc tmp if Que(tmp)=int_req then Moving 'there is an internl Request in Que so keep moving loop endif endif move_slow: tmp=RX_byte slow_timeout if tmp<>"s" then communication_error STOP: GOTO main communication_error: LCD_str "Comm Err" Cam_fail: lcd_str "Cam Failed" end ' ------------------------------------------------------------------------- ' Subroutine / Function / Task Code ' ------------------------------------------------------------------------- ' Use: LCD_INIT {single} ' -- initializes LCD in 4-bit mode ' -- defaults to multi-line; single-line if single.0 = 1 SUB GET_DIR ENDSUB Sub get_Requests tmp=0 put temp,que(0) to que(15) endsub SUB TX_BYTE ser_ctrl=1 SEROUT Ser_pin, Baud, __PARAM1 ' send the character ser_ctrl=0 endsub FUNC RX_Byte tmp=__param1 SERIN Ser_pin, Baud, __param1,tmp,timeout ' receive a byte goto rx_done timeout: __param1=255 'timeout flag rx_done: ENDFUNC SUB LCD_INIT LcdBus = %0011 ' 8-bit mode LCD_BLIP DELAY_MS 5 LCD_BLIP DELAY_US 125 LCD_BLIP LcdBus = %0010 ' 4-bit mode LCD_BLIP LCD_CMD %0000_1100 ' display on, no cursor LCD_CMD %0000_0110 ' auto-increment cursor ENDSUB ' ------------------------------------------------------------------------- ' Use: LCD_BLIP SUB LCD_BLIP Lcd_E = 1 DELAY_US 2 Lcd_E = 0 DELAY_US 50 ' instruction delay ENDSUB ' ------------------------------------------------------------------------- ' Use: LCD_CMD cmd -- send command to LCD ' -- sets buss to cmd (RS = 0) SUB LCD_CMD Lcd_RS = 0 ' command mode GOTO LCD_OUT ' jump over ENDSUB ENDSUB ' ------------------------------------------------------------------------- ' Use: LCD_OUT char ' -- send character to LCD SUB LCD_OUT swap __param1 'Swap upper and lower Nibbles LcdBus=__param1 LCD_BLIP swap __param1 Lcdbus=__param1 LCD_BLIP Lcd_RS=1 'go back to char Data mode ENDSUB ' ------------------------------------------------------------------------- ' Use: LCD_STR [string | Label] ' -- prints embedded string or z-string at Label SUB LCD_STR sAddr VAR __WPARAM12 ' address of string sChar VAR __PARAM1 ' character from string DO READINC sAddr, sChar ' get a character IF sChar = 0 THEN EXIT ' if 0, we're done LCD_OUT sChar ' print the character LOOP ENDSUB ' ------------------------------------------------------------------------- ' Use: LCD_SET_CRSR ' -- set cursor on (1) or off (0) SUB LCD_SET_CRSR crsrCmd VAR __PARAM2 crsrCmd = %0000_1100 ' display on, no cursor crsrCmd.1 = __PARAM1.0 ' set cursor to parameter LCD_CMD crsrCmd ENDSUB ' ------------------------------------------------------------------------- ' Use: DELAY_MS duration ' -- shell for PAUSE SUB DELAY_MS '{$IFUSED DELAY_MS} msDuration VAR __WPARAM12 PAUSE msDuration '{$ENDIF} ENDSUB ' ------------------------------------------------------------------------- ' Use: DELAY_US duration ' -- shell for PAUSEUS SUB DELAY_US '{$IFUSED DELAY_US} usDuration VAR __WPARAM12 PAUSEUS usDuration '{$ENDIF} ENDSUB ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=357773#m357780 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2009 (http://www.dotNetBB.com)