// --------------------------------------------------------------------------- // // New firmware for the Vaisala SPT11A manual paper tape reader // 4/24/2016 by Erik Baigar, Munich, Germany // // No warranties - feel free to use as desired // Credits and link to my web page are highly welcome // http://www.baigar.de/ // http://www.programmer-electronic-control.de/index.html // // To get in touch use email: erik@baigar.de // // --------------------------------------------------------------------------- // #include #include #include <8051.h> #define FALSE 0 #define TRUE 1 // -- RAM-Anschluesse #define Sprocket P3_2 #define Red P3_4 #define Green P3_3 #define Yellow P3_5 #define PRINTF printf // ---------------------------------------------------------------- #define BUFFER_SIZE 8 volatile unsigned char data tx_tail; // Transmit interrupt index. volatile unsigned char data tx_head; // Transmit write index. static bit is_txing; // True when transmitting a character. static unsigned char data tx_buf[BUFFER_SIZE]; // Transmit queue. // ---------------------------------------------------------------- // #### # # # # ##### // # # ## # # # // #### ##### # # # # # # // # # # # # # # // # # # # ## # # // #### # # # # # // ---------------------------------------------------------------- void init_ser (void) { tx_tail = 0; tx_head = 0; is_txing = FALSE; // Not transmitting SCON = 0x50; TMOD = (TMOD & 0x0F) | 0x20; TH1 = 252; // 256-(12000000/192)/2400 = 256-4 = 252 PCON = 0x80; // Double-clock, no power-down TR1 = 1; ES = 1; EA = 1; } // ---------------------------------------------------------------- // ### ###### ##### // # # # # # // # # # # # // # ###### # # // # # # # # # // # # # # # // ### # # #### # // ---------------------------------------------------------------- void SerInt (void) interrupt 4 using 2 { if (RI) // Receive character? { RI = 0; // clear receive flag } if (TI) // Transmit character? { TI = 0; // Clear transmitter flag. if (tx_head == tx_tail) // Check to see if anymore characters to send? is_txing = FALSE; // No, indicate to ser_write_byte to set TI next time. else { is_txing = TRUE; // TI interrupt will occur at end of this character. SBUF = tx_buf[tx_tail++]; // Transmit character out serial port. if (tx_tail >= BUFFER_SIZE) // Wrap pointer to beginning of buffer if at end. tx_tail = 0; } } } // --------------------------------------------------------------------------- // // ##### # # ##### #### # # ## ##### // # # # # # # # # # # # # # // # # # # # # ###### # # # # // ##### # # # # # # ###### ##### // # # # # # # # # # # # # // # #### # #### # # # # # # // // --------------------------------------------------------------------------- void putchar (char buf) { unsigned char next_head; tx_buf[tx_head] = buf; next_head = tx_head + 1; if (next_head >= BUFFER_SIZE) next_head = 0; // Wait until we can stick the next character into the queue. // prevent buffer over write while (next_head == tx_tail) { Red=0; }; tx_head = next_head; if (is_txing == FALSE) TI = TRUE; } // ------------------------------------------------------------------------------ // // # # ## # # # // ## ## # # # ## # // # ## # # # # # # # // # # ###### # # # # // # # # # # # ## // # # # # # # # // // ------------------------------------------------------------------------------ int j; main () { Red = 1; Green = 0; Yellow= 1; Green = 1; init_ser (); PRINTF ("Manual PTR, FW1.01, 4/24/2016\r\nErik Baigar, Germany\r\n\r\n"); Red=0; Green= 0; while (1==1) { j = 0; while (j<5) { if (Sprocket==0) { j++; } else { j=0;} ; } putchar((char)P1); Yellow=0; j = 0; while (j<5) { if (Sprocket==1) { j++; } else { j=0;} ; } Yellow=1; } }