/********************************************* This program was produced by the CodeWizardAVR V1.23.7a Light Automatic Program Generator © Copyright 1998-2002 HP InfoTech s.r.l. http://www.hpinfotech.ro e-mail:office@hpinfotech.ro Project : StampPlot Example interface Version : 0.62 Date : 12/13/2002 Author : Martin A. Hebel Company : SelmaWare Solutions Comments: www.selmaware.com Chip type : AT90LS8535 Clock frequency : 4.000000 MHz Memory model : Small Internal SRAM size : 512 External SRAM size : 0 Data Stack size : 128 *********************************************/ /******************************************** StampPlot configured for: UART 9600-8-N-1 Ouputs on port C - Switches control Inputs on port B - Displayed on lights and plotted digitla ADC on channels 0 and 1 Notes: StampPlot cannot handle very high speed data it is dependent on how much data is sent.. just analog for plotting?updating meters? etc. A deley of at least 100 mS is recommended StampPlot cannot send a null character, at least one of the virtual switch must be on for serially data to be sent back to the AVR. ********************************************/ #include <90s8535.h> #include #include // *********** StampPlot Function Prototypes ************** // Runs routine to configure StampPlot layout void plot_config(); /* Plots one of ten anlog channels of data plot_channel(channel number,Value); plot_channel(1,500); */ void plot_channel(char,int); /* plots 1 to 8 channels of digital plot_digital(number of bits LSB to MSB to plot, byte to plot digitall); plot_digital(2,129); */ void plot_digital(char, unsigned char); /* Sets the value indicated a gauge , 1-4 gauge_set(gauge number 1-4,gauge value); gauge_set(3,50); */ void gauge_set(char,int); /* sets the range of a gauge, 1-4 gauge_range(gauge number 1-4, low, high gauge_set(3,-100,100); */ void gauge_range(char,int,int); /* sets the upper and lower setpoints for a gauge, 1-4 gauge_setpoints(gauge number 1-4,low set, high set); gauge_set(3.-50,50); */ void gauge_setpoints(char,int,int); /* Enables the setpoint alarm for the specified gauge gauge_alarm(gauge number, value 1=on 2=off); gauge(3,1); */ void gauge_alarm(char,char); /* Sets the label of a gauge with a value see set_labels to set with text. gauge_label(gauge number 1-4,value); gauge_set(3,50); */ void gauge_label(char, int); /* Sets the state of light 0-7 as on or off light_set(light number 0-7, state 1=on 0=off) light_set(5,PINB.5); */ void light_set(char,char); /* Sets the state of all lights 0-7 based on byte sent lights_set(byte); lights_set(PINB); */ void lights_set(unsigned char); /* Sets the state of switches 0-7 as on or off switch_set(number 0-7, state 1=on 0=off) switch_set(5,1); */ void switch_set(char,char); /* Sets the state of all switches 0-7 based on byte sent switches_set(byte); switches_set(185); */ void switches_set(unsigned char); /* Reads returning data from stamp plot (a byte) which is the value of the switches as a single byte. For error prevention, 2 consecutive equal values must be read prior to the global variable switchByte being updated. data is also parsed into global variables switchBit[0] to switchBit[7] The configuration currenlly has a timer sending the byte from StampPlot every .250 Seconds switches_read(); PORTC=switchByte; PORTC.5=switchBit[5]; */ void switches_read(void); /* sets the labels of gauges, switches and lights manually modify the text values for your use in the function. */ void set_labels(void); // ************************************************************************** #define RXB8 1 #define TXB8 0 #define OVR 3 #define FE 4 #define UDRE 5 #define RXC 7 #define FRAMING_ERROR (1< (LAST_ADC_INPUT-FIRST_ADC_INPUT)) input_index=0; ADMUX=FIRST_ADC_INPUT+input_index; // Start the AD conversion ADCSR|=0x40; #asm pop r30 out sreg,r30 pop r31 pop r30 pop r27 pop r26 #endasm } #pragma savereg+ // Declare your global variables here unsigned char switchByte; char switchBit[7]; void main(void) { // Declare your local variables here unsigned char count; // Input/Output Ports initialization // Port A initialization // Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In // State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T PORTA=0x00; DDRA=0x00; // Port B initialization // Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In // State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T PORTB=0x00; DDRB=0x00; // Port C initialization // Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In // State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T PORTC=0x00; DDRC=0xFF; // Port D initialization // Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In // State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T PORTD=0x00; DDRD=0x00; // Timer/Counter 0 initialization // Clock source: System Clock // Clock value: Timer 0 Stopped TCCR0=0x00; TCNT0=0x00; // Timer/Counter 1 initialization // Clock source: System Clock // Clock value: Timer 1 Stopped // Mode: Normal top=FFFFh // OC1A output: Discon. // OC1B output: Discon. // Noise Canceler: Off // Input Capture on Falling Edge TCCR1A=0x00; TCCR1B=0x00; TCNT1H=0x00; TCNT1L=0x00; OCR1AH=0x00; OCR1AL=0x00; OCR1BH=0x00; OCR1BL=0x00; // Timer/Counter 2 initialization // Clock source: System Clock // Clock value: Timer 2 Stopped // Mode: Normal top=FFh // OC2 output: Disconnected ASSR=0x00; TCCR2=0x00; TCNT2=0x00; OCR2=0x00; // External Interrupt(s) initialization // INT0: Off // INT1: Off GIMSK=0x00; MCUCR=0x00; // Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x00; // UART initialization // Communication Parameters: 8 Data, 1 Stop, No Parity // UART Receiver: On // UART Transmitter: On // UART Baud rate: 9600 UCR=0x18; UBRR=0x19; //UCSRB=0x98 #asm ("sei") // Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off // Analog Comparator Output: Off ACSR=0x80; // ADC initialization // ADC Clock frequency: 125.000 kHz ADMUX=FIRST_ADC_INPUT; ADCSR=0xCD; // ***************** Run configuration routines ****************** plot_config(); // send configuration information gauge_range(1,0,1200); // set gauge 1 to 0-1200 gauge_setpoints(1,100,1100); // set gauge 1 setpoints 100 low, 1000 high gauge_range(2,-300,300); // set gauge 2 range -300 to 300 gauge_setpoints(2,-200,200); // set gauge 2 setpoints -200 low, 200 high gauge_alarm(1,1); // enable alarm on gauge 1 set_labels(); // call routin to set labels of gauges, etc switch_set(2,1); // turn switch 2 on putsf("!SPAN 0,1000\r"); // set Y axis span putsf("!PLOT 1\r"); // enable plotting putsf("!RSET\r"); // reset the plot while(1) { count++; // increment general counter delay_ms(500); // 500mS delay (appox.) printf("!STAT Switch Byte = %d\r",switchByte); // place data of sitchByte read in status box plot_channel(1,adc_data[0]); // plot analog channel 1 with ADC0 plot_channel(2,count); // plot analog channel 2 with count; gauge_set(1,adc_data[0]); // set gauge 1 value to ADC0 gauge_set(2,count); // set gauge 2 value to count gauge_label(2,count); // set gauge 2 label to count value plot_digital(4,PINB); // plot 4 lower bits of PINB in digital lights_set(PINB); // set Lights to PINB byte switches_read(); // go update switch variables PORTC=switchByte; // Set port C to read switch byte }; } void plot_channel(char num,int value) { //send string for plotting analog channel printf("\r^ACHN %d,%d,%d\r",num,value,num); } void plot_digital(char numBits, unsigned char value) { // create string of %10101 (example) for plotting digital int i; putsf("%"); for (i=1;i<=numBits;i++) { printf("%d",(value & 1)); value = value >> 1; } putsf("\r"); } void gauge_set(char num,int value) { // send string to update gauge, ONLY if changed from last time static int lastValue; if(value != lastValue) printf("\r!O G%d=%d\r",num,value); lastValue = value; } void gauge_range(char num,int low,int high) { // send string to set gauge range printf("\r!O G%d=,%d,%d\r",num,low,high); } void gauge_setpoints(char num,int low,int high) { // send string to update gauge setpoints printf("\r!O G%d=,,,%d,%d\r",num,low,high); } void gauge_alarm(char num,char value) { // set event code for gauge depending on alarm set or not if (value ==1) { // choice of system bell or wav file for alarm printf("\r!O G%d.C=~PWAV gbell.wav\r",num); // printf("\r!O G%d.C=!BELL\r",num); } else { printf("\r!O G%d.C= \r",num); } } void gauge_label(char num,int value) { // send string to set gauge label printf("!O txtG%d=%d\r",num,value); } void light_set(char num,char state) { // send string to set individual light printf("!O L%d=%d\r",num,state); } void lights_set(unsigned char value) { // sends 8 strings for each light based on bit values in byte // perform ONLY if different than last time. int i; int t; static unsigned char lastValue; if (value != lastValue) { for (i=0;i<=7;i++) { t=value; printf("!O L%d=%d\r",i,((t>>i)&1)); } } lastValue = value; } void switch_set(char num,char state) { // send string to set individual switch state printf("!O S%d=%d\r",num,state); } void switches_set(unsigned char value) { // sends 8 strings for each switch based on bit values in byte // perform ONLY if different than last time. int i; int t; static unsigned char lastValue; if (value != lastValue) { for (i=0;i<=7;i++) { t=value; printf("!O S%d=%d\r",i,((t>>i)&1)); } } lastValue = value; } void switches_read() { // returning byte is switch state from StampPlot // must have 2 consective equal values // before switchByte and switchBit[] global variables are updated int i; int t; unsigned char data; unsigned char status; static unsigned char inLast; status=USR; data=UDR; if (((status & (FRAMING_ERROR))==0) && (inLast==data)) { switchByte=data; for (i=0;i<=7;i++) { t=switchByte>>i; switchBit[i]=t & 1; } } inLast=data; } void plot_config(void) { // send configuration strings char i; delay_ms(1000); putsf("\r!NPSU 0\r"); // new plot start up off (prevent other macro from running) putsf("!NEWP\r"); // start a new plot putsf("!O Clear\r"); // clear all plot objects putsf("!PPER 80,80\r"); // set percent size of plot 80% X and 80% Y putsf("!O oBack=7\r"); // set background color to grey // create 4 gauges G1 to G4 putsf("!POBJ oGauge.G1=81.,94.,8.,30.,0,100,0,100\r"); putsf("!POBJ oGauge.G2=91.,94.,8.,30.,0,100,0,100\r"); putsf("!POBJ oGauge.G3=81.,50.,8.,30.,0,100,0,100\r"); putsf("!POBJ oGauge.G4=91.,50.,8.,30.,0,100,0,100\r"); // ceate 4 gauge labels txtG1 to txtG4 putsf("!POBJ oLabel.txtG1=81.,98.,8.,4.,Gauge 1,0,14,9,1\r"); putsf("!POBJ oLabel.txtG2=91.,98.,8.,4.,Gauge 2,0,14,9,1\r"); putsf("!POBJ oLabel.txtG3=81.,54.,8.,4.,Gauge 3,0,14,9,1\r"); putsf("!POBJ oLabel.txtG4=91.,54.,8.,4.,Gauge 4,0,14,9,1\r"); // create 8 switches (S0-S7), lights (L0-L7) and labels for switches (txtS0-7) and lights (txtL0-7) for (i=0;i<8;i++) { delay_ms(100); printf("!POBJ oImgBut.L%d=%d,17,4,7,comp\\LED_red_0.jpg,0,comp\\led_red_1.jpg,0\r",i,(73-i*10)); printf("!POBJ oImgBut.S%d=%d,7.,4.,7.,comp\\switch_0.jpg,0,comp\\switch_1.jpg,0\r",i,(73-i*10)); printf("!POBJ oLabel.txtL%d=%d,20.,10.,3.,LT %d,0,14,7,1\r",i,(70-i*10),i); printf("!POBJ oLabel.txtS%d=%d,10.,10.,3.,SW %d,0,14,7,1\r",1,(70-i*10),i); } delay_ms(2000); // 2 second delay to allow stampplot to catch up putsf("!O S*.C=~IWAV stapler.wav\r"); // set sound effects for all (S*) switches putsf("!O S7=1\r"); // set S7 on putsf("!TITL == AVR INTERFACE ==\r"); // set plot title putsf("!SHFT 1\r"); // enable plot shifting putsf("!FLSH 1\r"); // enable data flushing putsf("!PNTS 1000\r"); // Store 1000 points of data putsf("!O oTimer0=0.250\r"); // set plot timer 0 to .250 // set timer code to send byte value of switches serially putsf("!O oTimer0.C=!BSND [(S7)(S6)(S5)(S4)(S3)(S2)(S1)(S0),DAC]\r"); } void set_labels(void) { // set labels, manually configure for application printf("!O txtG1=ADC 0\r"); // printf("!O txtG2=? \r"); // printf("!O txtG3=? \r"); // printf("!O txtG4=?.\r"); // printf("!O txtL0=? \r"); // printf("!O txtL1=? \r"); // printf("!O txtL2=? \r"); // printf("!O txtL3=? \r"); // printf("!O txtL4=? \r"); // printf("!O txtL5=? \r"); // printf("!O txtL6=? \r"); // printf("!O txtL7=? \r"); // printf("!O txtS0=? \r"); // printf("!O txtS1=? \r"); // printf("!O txtS2=? \r"); // printf("!O txtS3=? \r"); // printf("!O txtS4=? \r"); // printf("!O txtS5=? \r"); // printf("!O txtS6=? \r"); // printf("!O txtS7=? \r"); }