Program Code-Vision AVR PENGUJIAN RANGKAIAN

4.5 Program Code-Vision AVR

This program was created by the CodeWizardAVR V2.60 Standard Automatic Program Generator © Copyright 1998-2012 Pavel Haiduc, HP InfoTech s.r.l. http:www.hpinfotech.com Project : Version : Date : 12202012 Author : Company : Comments: Chip type : ATmega8535 Program type : Application AVR Core Clock frequency: 7.372800 MHz Memory model : Small External RAM size : 0 Data Stack size : 128 include mega8535.h include delay.h include std_tool_sio.h define sdt PORTC.2 define sclk PORTC.3 define soe PORTC.4 Declare your global variables here unsigned char s, m, j; Universitas Sumatera Utara eeprom unsigned char exp; void disp unsigned char n { if n == 0shift_out 0x81; if n == 1shift_out 0xcf; if n == 2shift_out 0x92; if n == 3shift_out 0x86; if n == 4shift_out 0xcc; if n == 5shift_out 0xa4; if n == 6shift_out 0xa0; if n == 7shift_out 0x8f; if n == 8shift_out 0x80; if n == 9shift_out 0x84; } void t_out unsigned int ttt { unsigned char rat, pul, sat, sisa; rat = ttt100; sisa = ttt - rat 100; pul = sisa10; sat = sisa10; disprat; disppul; dispsat; } External Interrupt 2 service routine interrupt [EXT_INT2] void ext_int2_isrvoid { Place your code here } Universitas Sumatera Utara Timer 0 overflow interrupt service routine interrupt [TIM0_OVF] void timer0_ovf_isrvoid { Reinitialize Timer 0 value TCNT0=0x4C; Place your code here PORTD = 0x55; } Timer1 overflow interrupt service routine interrupt [TIM1_OVF] void timer1_ovf_isrvoid { Reinitialize Timer1 value TCNT1H=0x1F00 8; TCNT1L=0x1F00 0xff; Place your code here PORTD = 0xaa; s++; if s 117 { s = 0; m++; if m 117 { m = 0; j++; if j 120 exp = 1; } } } define ADC_VREF_TYPE 0REFS1 | 1REFS0 | 0ADLAR Read the AD conversion result unsigned int read_adcunsigned char adc_input Universitas Sumatera Utara { ADMUX=adc_input | ADC_VREF_TYPE; Delay needed for the stabilization of the ADC input voltage delay_us10; Wait for the AD conversion to complete while ADCSRA 1ADIF==0; ADCSRA|=1ADIF; return ADCW; } void mainvoid { Declare your local variables here unsigned int t, t0, t1, t2, t3, t4, t5; InputOutput Ports initialization Port A initialization Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In DDRA=0DDA7 | 0DDA6 | 0DDA5 | 0DDA4 | 0DDA3 | 0DDA2 | 0DDA1 | 0DDA0; State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T PORTA=0PORTA7 | 0PORTA6 | 0PORTA5 | 0PORTA4 | 0PORTA3 | 0PORTA2 | 0PORTA1 | 0PORTA0; Port B initialization Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In DDRB=0DDB7 | 0DDB6 | 0DDB5 | 0DDB4 | 0DDB3 | 0DDB2 | 0DDB1 | 0DDB0; State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T PORTB=0PORTB7 | 0PORTB6 | 0PORTB5 | 0PORTB4 | 0PORTB3 | 0PORTB2 | 0PORTB1 | 0PORTB0; Port C initialization Function: Bit7=In Bit6=In Bit5=In Bit4=Out Bit3=Out Bit2=Out Bit1=In Bit0=In DDRC=0DDC7 | 0DDC6 | 0DDC5 | 1DDC4 | 1DDC3 | Universitas Sumatera Utara 1DDC2 | 0DDC1 | 0DDC0; State: Bit7=T Bit6=T Bit5=T Bit4=0 Bit3=0 Bit2=0 Bit1=T Bit0=T PORTC=0PORTC7 | 0PORTC6 | 0PORTC5 | 0PORTC4 | 0PORTC3 | 0PORTC2 | 0PORTC1 | 0PORTC0; Port D initialization Function: Bit7=Out Bit6=Out Bit5=Out Bit4=Out Bit3=Out Bit2=Out Bit1=Out Bit0=Out DDRD=1DDD7 | 1DDD6 | 1DDD5 | 1DDD4 | 1DDD3 | 1DDD2 | 1DDD1 | 1DDD0; State: Bit7=0 Bit6=0 Bit5=0 Bit4=0 Bit3=0 Bit2=0 Bit1=0 Bit0=0 PORTD=0PORTD7 | 0PORTD6 | 0PORTD5 | 0PORTD4 | 0PORTD3 | 0PORTD2 | 0PORTD1 | 0PORTD0; TimerCounter 0 initialization Clock source: System Clock Clock value: 7.200 kHz Mode: Normal top=0xFF OC0 output: Disconnected Timer Period: 25 ms TCCR0=0WGM00 | 0COM01 | 0COM00 | 0WGM01 | 1CS02 | 0CS01 | 1CS00; TCNT0=0x4C; OCR0=0x00; TimerCounter 1 initialization Clock source: System Clock Clock value: 115.200 kHz Mode: Normal top=0xFFFF OC1A output: Disconnected OC1B output: Disconnected Noise Canceler: Off Input Capture on Falling Edge Timer Period: 0.5 s Timer1 Overflow Interrupt: On Universitas Sumatera Utara Input Capture Interrupt: Off Compare A Match Interrupt: Off Compare B Match Interrupt: Off TCCR1A=0COM1A1 | 0COM1A0 | 0COM1B1 | 0COM1B0 | 0WGM11 | 0WGM10; TCCR1B=0ICNC1 | 0ICES1 | 0WGM13 | 0WGM12 | 0CS12 | 1CS11 | 1CS10; TCNT1H=0x1F; TCNT1L=0x00; ICR1H=0x00; ICR1L=0x00; OCR1AH=0x00; OCR1AL=0x00; OCR1BH=0x00; OCR1BL=0x00; TimerCounter 2 initialization Clock source: System Clock Clock value: Timer2 Stopped Mode: Normal top=0xFF OC2 output: Disconnected ASSR=0AS2; TCCR2=0WGM20 | 0COM21 | 0COM20 | 0WGM21 | 0CS22 | 0CS21 | 0CS20; TCNT2=0x00; OCR2=0x00; TimersCounters Interrupts initialization TIMSK=0OCIE2 | 0TOIE2 | 0TICIE1 | 0OCIE1A | 0OCIE1B | 1TOIE1 | 0OCIE0 | 1TOIE0; External Interrupts initialization INT0: Off INT1: Off INT2: On Universitas Sumatera Utara INT2 Mode: Falling Edge GICR|=0INT1 | 0INT0 | 1INT2; MCUCR=0ISC11 | 0ISC10 | 0ISC01 | 0ISC00; MCUCSR=0ISC2; GIFR=0INTF1 | 0INTF0 | 1INTF2; USART initialization USART disabled UCSRB=0RXCIE | 0TXCIE | 0UDRIE | 0RXEN | 0TXEN | 0UCSZ2 | 0RXB8 | 0TXB8; Analog Comparator initialization Analog Comparator: Off ACSR=1ACD | 0ACBG | 0ACO | 0ACI | 0ACIE | 0ACIC | 0ACIS1 | 0ACIS0; ADC initialization ADC Clock frequency: 57.600 kHz ADC Voltage Reference: AVCC pin ADC High Speed Mode: Off ADC Auto Trigger Source: Timer0 Overflow ADMUX=ADC_VREF_TYPE; ADCSRA=1ADEN | 0ADSC | 1ADATE | 0ADIF | 0ADIE | 1ADPS2 | 1ADPS1 | 1ADPS0; SFIOR=1ADHSM | 1ADTS2 | 0ADTS1 | 0ADTS0; SPI initialization SPI disabled SPCR=0SPIE | 0SPE | 0DORD | 0MSTR | 0CPOL | 0CPHA | 0SPR1 | 0SPR0; TWI initialization TWI disabled TWCR=0TWEA | 0TWSTA | 0TWSTO | 0TWEN | 0TWIE; Universitas Sumatera Utara Global enable interrupts asmsei t5 = 0; t4 = 0; t3 = 0; t2 = 0; t1 = 0; t0 = 0; if exp == 0xff exp = 0; while 1 { Place your code here t5 = t4; t4 = t3; t3 = t2; t2 = t1; t1 = t0; t0 = read_adc0 5; t = t0 + t1 + t2 +t3 + t4 + t56; delay_ms100; soe = 0; t_outt; soe = 1; delay_ms100; if exp == 1 { disp123; delay_ms1000; } } } Universitas Sumatera Utara

4.6 Data Pengukuran