/***************************************************** This program was produced by the CodeWizardAVR V2.05.5a Standard Automatic Program Generator © Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l. http://www.hpinfotech.com Project : Version : Date : 3/18/2015 Author : Larry Kalder, L1 Company : 108 Melva Ct Windsor CA95492 Comments: Chip type : ATmega88 Program type : Application AVR Core Clock frequency: 8.000000 MHz Memory model : Small External RAM size : 0 Data Stack size : 256 *****************************************************/ #define IDX_MAX 22 #define FACTOR 8000 #include // for tolower() #include #include #include #include void initialization(void); #define RXB8 1 #define TXB8 0 #define UPE 2 #define OVR 3 #define FE 4 #define UDRE 5 #define RXC 7 #define FRAMING_ERROR (1< // VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS V //VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS // VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS V //VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS signed int counter, flag, fred, temp; // VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS V //VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS // VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS V //VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS VARS // Timer 1 output compare A interrupt service routine interrupt [TIM1_COMPA] void timer1_compa_isr(void) { flag=1; if(++temp > 200){ temp=0; fred++; } if(fred > 9)fred=0; if(++counter > 3) counter = 0; } // each pair of segments is controlled by one terminal. each terminal gets refreshed voltage // every 10mS for 40mS then repeats. These 4 voltages are contained in one byte of info. void main(void) // { // both on 0101 // initialization(); // first only (a of ab, c of ce, f of fg, d) 0011 // Global enable interrupts // #asm("sei") // second only (b of ab, e of ce etc) 1100 // while (1) // both off 1010 { // would put these in std place but don't care now // #define ZERO 0x5535 // a #define ONE 0xC3AA // | | #define TWO 0x5CC5 // f | | b #define THREE 0x53C5 // ab seg / ec pair / fg pair / d pair // -g-| #define FOUR 0xC35A // 1100 b only / 0011 c only / 0101 both fg / 1010 d off // e | c #define FIVE 0x3355 // combination for "4" // | #define SIX 0xA555 // d #define SEVEN 0x53AA // #define EIGHT 0x5555 // #define NINE 0x535A // 4 hx numbers for the 4 terminals of the glass // this is to put voltage or ground to each pin of LCD glass at the proper time // each hx has 4 bits, 1 for ea 10mS of time for each terminal // in relation to the com1 and com2 voltages. by contolling the v and gnd of each // segment at the same time the coms are high low or medium, the segments see AC. // the coms never change, are identical but 180 deg out of phase to each other // see Protel schematics for patterns // for each numeral 16 bits of info needed if(flag) com(); if(fred==0)digit_1(ZERO); else if (fred==1)digit_1(ONE); else if (fred==2)digit_1(TWO); else if (fred==3)digit_1(THREE); else if (fred==4)digit_1(FOUR); // clunky quick way to scroll through 0-9 else if (fred==5)digit_1(FIVE); else if (fred==6)digit_1(SIX); else if (fred==7)digit_1(SEVEN); else if (fred==8)digit_1(EIGHT); else if (fred==9)digit_1(NINE); } } //START START START START START START START START START START void com(void) { flag=0; switch (counter) { case 0: PORTD.6=1; // this creates the patterns shown in the Protel schematics PORTD.7=0; // by having the segments on or off at the same time the coms are high/med/low the segment is on or off. PORTD.2=1; // by looking at the coms WRT the segment you can see how the segment sees AC when only DC is used. PORTD.3=1; // segments are only high or low, coms high/med/low. but using the segment as gnd for scope w/ probe on com break; // you will see a more complex pattern. case 1: PORTD.6=0; PORTD.7=0; PORTD.2=1; PORTD.3=0; break; case 2: PORTD.6=1; // could put this in interrupt but thought all functions would have to be in int so found a way for this PORTD.7=1; // to work here then left it. PORTD.2=1; PORTD.3=0; break; case 3: PORTD.6=1; PORTD.7=0; PORTD.2=0; PORTD.3=0; break; default: counter = 0; break; }; } void digit_1(int select) { // hex C 3 5 A sent down in call to display number 4 // using the digit "4" as example: 1100 0011 0101 1010 spaces added for readability #define BIT_MASK 1 // ab pair would use defines instead of PORTC.0 etc but don't care. switch (counter) { case 0: PORTC.0=(select >> 15); // t1 when counter == 0, takes var select, R shift 15 places, assigns 1 to PORTC.0. break; // Keeps being called by main and counter==0 for 10mS. // After 10mS counter ticks and PORTC.0 is assigned next value case 1: PORTC.0=(select >> 14) & BIT_MASK; // t2 takes select, R shift 14 places, applies mask, assigns it 1 (2nd 1 from 1100) break; case 2: PORTC.0=(select >> 13) & BIT_MASK; // t3 10 mS later shifts/masks, assigns next bit (1st 0 from 1100) break; case 3: PORTC.0=(select >> 12) & BIT_MASK; // t4 10 mS later shifts/masks assigns to PORTC.O (last 0 from 1100) break; default: counter = 0; break; }; // ce pair switch (counter) { case 0: PORTC.1=(select >> 11) & BIT_MASK; break; case 1: PORTC.1=(select >> 10) & BIT_MASK; break; case 2: PORTC.1=(select >> 9) & BIT_MASK; break; case 3: PORTC.1=(select >> 8) & BIT_MASK; break; default: counter = 0; break; }; // fg pair switch (counter) { case 0: PORTC.2=(select >> 7) & BIT_MASK; break; case 1: PORTC.2=(select >> 6) & BIT_MASK; break; case 2: PORTC.2=(select >> 5) & BIT_MASK; break; case 3: PORTC.2=(select >> 4) & BIT_MASK; break; default: counter = 0; break; }; // d seg switch (counter) { case 0: PORTC.3=(select >> 3) & BIT_MASK; break; case 1: PORTC.3=(select >> 2) & BIT_MASK; break; case 2: PORTC.3=(select >> 1) & BIT_MASK; break; case 3: PORTC.3=select & BIT_MASK; break; default: counter = 0; break; }; } void initialization(void) { // Declare your local variables here // Crystal Oscillator division factor: 1 #pragma optsize- CLKPR=0x80; CLKPR=0x00; #ifdef _OPTIMIZE_SIZE_ #pragma optsize+ #endif // Input/Output Ports initialization // Port B initialization // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out // State7=0 State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0 PORTB=0x00; DDRB=0xFF; // Port C initialization // Func6=In Func5=In Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out // State6=T State5=T State4=0 State3=0 State2=0 State1=0 State0=0 PORTC=0x00; DDRC=0x1F; // Port D initialization // Func7=Out Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out // State7=0 State6=1 State5=1 State4=1 State3=1 State2=1 State1=1 State0=1 PORTD=0x7F; DDRD=0xFF; // Timer/Counter 0 initialization // Clock source: System Clock // Clock value: Timer 0 Stopped // Mode: CTC top=OCR0A // OC0A output: Disconnected // OC0B output: Disconnected TCCR0A=0x02; TCCR0B=0x00; TCNT0=0x00; OCR0A=0x00; OCR0B=0x00; // Timer/Counter 1 initialization // Clock source: System Clock // Clock value: 8000.000 kHz // Mode: CTC top=OCR1A // OC1A output: Discon. // OC1B output: Discon. // Noise Canceler: Off // Input Capture on Falling Edge // Timer 1 Overflow Interrupt: Off // Input Capture Interrupt: Off // Compare A Match Interrupt: On // Compare B Match Interrupt: Off TCCR1A=0x00; TCCR1B=0x0D; TCNT1H=0x00; TCNT1L=0x00; ICR1H=0x00; ICR1L=0x00; OCR1AH=0x00; OCR1AL=0x21; // 21 = 4.2 mS 43 = 8.4 mS OCR1BH=0x00; OCR1BL=0x03; // Timer/Counter 2 initialization // Clock source: System Clock // Clock value: Timer 2 Stopped // Mode: Normal top=FFh // OC2A output: Disconnected // OC2B output: Disconnected ASSR=0x00; TCCR2A=0x00; TCCR2B=0x00; TCNT2=0x00; OCR2A=0x00; OCR2B=0x00; // External Interrupt(s) initialization // INT0: Off // INT1: Off // Interrupt on any change on pins PCINT0-7: Off // Interrupt on any change on pins PCINT8-14: Off // Interrupt on any change on pins PCINT16-23: Off EICRA=0x00; EIMSK=0x00; PCICR=0x00; // Timer/Counter 0 Interrupt(s) initialization TIMSK0=0x00; // Timer/Counter 1 Interrupt(s) initialization TIMSK1=0x02; // Timer/Counter 2 Interrupt(s) initialization TIMSK2=0x00; // USART initialization // Communication Parameters: 8 Data, 1 Stop, No Parity // USART Receiver: On // USART Transmitter: On // USART0 Mode: Asynchronous // USART Baud rate: 9600 UCSR0A=0x00; UCSR0B=0xD8; UCSR0C=0x06; UBRR0H=0x00; UBRR0L=0x33; // Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80; ADCSRB=0x00; // SPI initialization // SPI Type: Master // SPI Clock Rate: 2000.000 kHz // SPI Clock Phase: Cycle Half // SPI Clock Polarity: Low // SPI Data Order: MSB First SPCR=0x50; SPSR=0x00; }