In SX Microcontrollers, SX/B Compiler and SX-Key Tool, Hollov wrote: Hi Bean, Here ia the code: ' ------------------------------------------------------------------------- ' Program Description ' ------------------------------------------------------------------------- ' 1. Device address: ' ' All PORTs are inputs with intenal pullup ' ' Addr_0 - RA0 ' Addr_1 - RA1 ' Addr_2 - RA2 ' Addr_3 - RA3 ' ' 2. IR LED driver IC (U427B pin 1) control: ' ' Ir_Led - RB6 - Output ' ' 3. Control LED driver use IR driver IC STANDBY circuit (U427B pin 2): ' ' Contr_Led - RB7 - Output ' ' 4. RS485 IC (SN75176B) reveiver: ' ' Ser_In - RB4 - Input ' ' 5. RS485 IC (SN75176B) transmitter: ' ' Ser_Out - RB5 - Output ' ' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- DEVICE SX48, OSCXT2', TURBO, STACKX, OPTIONX FREQ 4_000_000 ID "SXB_AITR" ' ------------------------------------------------------------------------- ' IO Pins ' ------------------------------------------------------------------------- Addr VAR RA ' device address TRIS_A_PORT VAR TRIS_A PLP_A_PORT VAR PLP_A Ser_In VAR RB.4 ' RS485 input Ser_Out VAR RB.5 ' RS485 output Ir_Led VAR RB.6 ' IR LED driver output Ctrl_Led VAR RB.7 ' control LED output TRIS_B_PORT VAR TRIS_B TRIS_C_PORT VAR TRIS_C Ir_Mod VAR RC.2 ' IR LED modulator signal ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- Addr_Mem VAR Byte ' address memory Led_On_Time VAR Byte ' control LED on timer Led_Off_Time VAR Byte ' control LED off timer Mode_Bit VAR Bit ' mode bit Led_Flag VAR Bit ' control LED staus flag ' ------------------------------------------------------------------------- INTERRUPT 200 ' ------------------------------------------------------------------------- ISR_Start: IF Mode_Bit = 1 THEN Test_Blink IF Led_Flag = 0 THEN Led_Off Led_On: ' LED normal mode Led_Flag = 1 ' set control LED flag to one HIGH Ctrl_Led ' switch on control LED Led_Off_Time = 0 ' clear control LED off timer INC Led_On_Time ' increment control LED on timer IF Led_On_Time = 5 THEN Led_Off GOTO ISR_Exit Led_Off: Led_Flag = 0 ' set control LEd flag to zero LOW Ctrl_Led ' switch off control LED Led_On_Time = 0 ' clear controll LED on timer INC Led_Off_Time ' increment control LED on timer IF Led_Off_Time = 250 THEN Led_On GOTO ISR_Exit Test_Blink: ' LED test mode INC Led_On_Time IF Led_On_Time = 100 THEN Led_Toggle ' LED blinking on 1 Hz GOTO ISR_Exit Led_Toggle: TOGGLE Ctrl_Led ' toggle control LED Led_On_Time = 0 ' clear control LED on timer ISR_Exit: RETURNINT '156 ' {cycles} 200.32 Hz ' ========================================================================= PROGRAM Start ' ========================================================================= ' ------------------------------------------------------------------------- ' Subroutine Declarations ' ------------------------------------------------------------------------- ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- Start: ' initialization TRIS_A_PORT = %1111 ' configuring A PORT to input PLP_A_PORT =%0000 ' pullup A port TRIS_B_PORT = %0001_1111 ' configuring B PORT ' RB7,RB6,RB5 output, ' other RB input HIGH Ctrl_Led ' set RB7 low LOW Ir_Led ' set RB6 Low LOW Ser_Out ' set RB5 low TRIS_C_PORT = %1111_1101 ' configuring C PORT ' RC2 output, others input LOW Ir_Mod ' set RC2 low Addr_Mem = 0 ' clear address memory Led_On_Time = 0 ' control LED on timer Led_Off_Time = 0 ' control LED off timer Mode_Bit = 0 ' set mode bit to test mode Led_Flag = 1 ' set control LED status flag to one 'OPTION = $86 ' enable interrupt with prescaler 1:128 Main: ' main program Read_Addr: ' read device addres ' Addr_Mem = Addr 'Mode_Sel: ' mode selection ' IF Addr_Mem = 0 THEN Test_Mode 'Command_Mode: ' entering command mode ' Mode_Bit = 1 ' GOTO Read_Addr Test_Mode: ' entering test mode Mode_Bit = 0 Ctrl_Led = ~Ctrl_Led PAUSE 500 GOTO Read_Addr END Regards Spiller ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=246929#m246961 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)