/* */ #include <ioavr.h> #include <intrinsics.h> #include <ina90.h> /* */ // #define F_CPU 16000000 // #define UCHAR unsigned char #define UINT unsigned int // //0 #define SEG_0 ~(0x3f) //1 #define SEG_1 ~(0x06) //2 #define SEG_2 ~(0x5b) //3 #define SEG_3 ~(0x4F) //4 #define SEG_4 ~(0x66) //5 #define SEG_5 ~(0x6d) //6 #define SEG_6 ~(0x7d) //7 #define SEG_7 ~(0x07) //8 #define SEG_8 ~(0x7F) //9 #define SEG_9 ~(0x6F) //A #define SEG_A ~(0x77) //b #define SEG_b ~(0x7c) //C #define SEG_C ~(0x39) //d #define SEG_d ~(0x5e) //E #define SEG_E ~(0x79) //F #define SEG_F ~(0x71) // #define SEG_MASK (0x7F) // // // #define SEG_1DEC_PORT PORTD // #define SEG_2DEC_PORT PORTB // #define SEG_3DEC_PORT PORTA // #define SEG_1DEC_DDR DDRD // #define SEG_2DEC_DDR DDRB // #define SEG_3DEC_DDR DDRA /* */ // #define DELAY_US(us) __delay_cycles((F_CPU / 1000000) * (us)); // #define DELAY_MS(ms) __delay_cycles((F_CPU / 1000) * (ms)); // #define SEG_PORTS_INIT() ( SEG_3DEC_DDR |= SEG_MASK );\ ( SEG_2DEC_DDR |= SEG_MASK );\ ( SEG_1DEC_DDR |= SEG_MASK ); // #define SEG_PORTS_CLEAR() ( SEG_3DEC_PORT &=~ SEG_MASK );\ ( SEG_2DEC_PORT &=~ SEG_MASK );\ ( SEG_1DEC_PORT &=~ SEG_MASK ); // #define SEG_PORTS_OUT(x,y,z) ( SEG_3DEC_PORT |= ( x & SEG_MASK ) );\ ( SEG_2DEC_PORT |= ( y & SEG_MASK ) );\ ( SEG_1DEC_PORT |= ( z & SEG_MASK ) ); /* */ // const unsigned char numbers[16] = { SEG_0, //0 SEG_1, //1 SEG_2, //2 SEG_3, //3 SEG_4, //4 SEG_5, //5 SEG_6, //6 SEG_7, //7 SEG_8, //8 SEG_9, //9 SEG_A, //A SEG_b, //b SEG_C, //C SEG_d, //d SEG_E, //E SEG_F //F }; // UINT i = 0; /* ** Name: Seg_Write() ** Description: ** ** Parameters: UINT dec3number 0 - 999 ** Returns: none */ void Seg_Write(UINT dec3number) { // UCHAR dec3 = 0 , dec2 = 0 , dec1 = 0; // 4 // dec3number = dec3number % 1000; // dec3 = dec3number / 100; // dec3number = dec3number % 100; // dec2 = dec3number / 10; // dec1 = dec3number % 10; // // SEG_PORTS_CLEAR(); // 3- // // SEG_PORTS_OUT( numbers[dec3], // numbers[dec2], // numbers[dec1] // ); }//end func /* ** Name: main() ** Description: , ** Parameters: none ** Returns: none */ // void main( void ) { // // SEG_PORTS_INIT(); // Seg_Write(888); // DELAY_MS(3000); // i=0; // for(;;) { // Seg_Write(i); // i++; // ? // if (i == 1000) i=0; // 100 DELAY_MS(100); }//end for }
/* */ #include <ioavr.h> #include <intrinsics.h> #include <ina90.h> /* */ // #define F_CPU 16000000 // #define UINT unsigned int /* */ // #define DELAY_US(us) __delay_cycles((F_CPU / 1000000) * (us)); // #define DELAY_MS(ms) __delay_cycles((F_CPU / 1000) * (ms)); /* */ // - UINT ADC_Result = 0; /* */ // void main( void ) { // // // 7- D DDRD_DDD7 = 1; // 7- D "0" PORTD_PORTD7 = 0; // // 7- A DDRA_DDA7 = 0; // PORTA_PORTA7 = 0; ADMUX_MUX0 = 1; // ADMUX_MUX1 = 1; ADMUX_MUX2 = 1; ADCSRA_ADEN = 1; // ADCSRA_ADPS0 = 1; // 16 / 128 = 125 ADCSRA_ADPS1 = 1; // 50-200 ADCSRA_ADPS2 = 1; // 13 125 13 / 125000 = 104 // for(;;) { // _NOP(); // 7- D "0" "1" "1" "0" // PORTD_PORTD7 ^= 1; // - ADCSRA_ADSC = 1; // - ? // (104 ) while (ADCSRA_ADIF == 0); // _NOP(); // - ADC_Result = ADC; // //ADC_Result = ADCL; // //ADC_Result += (ADCH << 8); // // ADCSRA_ADIF=1; // 100 (1/0,1 = 10 - ) DELAY_MS(100); }//end for }//end main
/* */ #include <ioavr.h> #include <intrinsics.h> #include <ina90.h> /* */ // #define F_CPU 16000000 // #define UINT unsigned int // // #define LED_DDR DDRD #define LED_PORT PORTD #define LED_PIN DDD7 // #define ADC_IN_DDR DDRA #define ADC_IN_PORT PORTA #define ADC_IN_DDR_PIN DDA7 #define ADC_IN_PORT_PIN PORTA7 // #define ADC0 (0<<MUX2)|(0<<MUX1)|(0<<MUX0) #define ADC1 (0<<MUX2)|(0<<MUX1)|(1<<MUX0) #define ADC2 (0<<MUX2)|(1<<MUX1)|(0<<MUX0) #define ADC3 (0<<MUX2)|(1<<MUX1)|(1<<MUX0) #define ADC4 (1<<MUX2)|(0<<MUX1)|(0<<MUX0) #define ADC5 (1<<MUX2)|(0<<MUX1)|(1<<MUX0) #define ADC6 (1<<MUX2)|(1<<MUX1)|(0<<MUX0) #define ADC7 (1<<MUX2)|(1<<MUX1)|(1<<MUX0) // #define ADC_F_CPU_DIV_2 (0<<ADPS2)|(0<<ADPS1)|(1<<ADPS0) #define ADC_F_CPU_DIV_4 (0<<ADPS2)|(0<<ADPS1)|(1<<ADPS0) #define ADC_F_CPU_DIV_8 (0<<ADPS2)|(1<<ADPS1)|(0<<ADPS0) #define ADC_F_CPU_DIV_16 (0<<ADPS2)|(1<<ADPS1)|(1<<ADPS0) #define ADC_F_CPU_DIV_32 (1<<ADPS2)|(0<<ADPS1)|(0<<ADPS0) #define ADC_F_CPU_DIV_64 (1<<ADPS2)|(1<<ADPS1)|(0<<ADPS0) #define ADC_F_CPU_DIV_128 (1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0) /* */ // #define LED_INIT() ( LED_DDR |= (1<<LED_PIN) ); // #define LED_LOW() ( LED_PORT &=~ (1<<LED_PIN) ); // #define LED_HIGH() ( LED_PORT |= (1<<LED_PIN) ); // #define LED_TOG() ( LED_PORT ^= (1<<LED_PIN) ); // #define ADC_IN_INIT() ( ADC_IN_DDR &= ~(0<<ADC_IN_DDR_PIN) );\ ( ADC_IN_PORT |= (0<<ADC_IN_PORT_PIN) ); // #define ADC_SET_CHAN(x) ( ADMUX |= x ); // #define ADC_ON() ( ADCSRA |= (1<<ADEN) ); // #define ADC_OFF() ( ADCSRA &=~ (1<<ADEN) ); // #define ADC_SET_CLK_DIV(x) ( ADCSRA |= x ); // - #define ADC_START_CONV() ( ADCSRA |= (1<<ADSC) ); // - #define ADC_RES_READY() ( ADCSRA & (1<<ADIF) ) // - #define ADC_FLAG_CLEAR() ( ADCSRA |= (1<<ADIF) ); // #define DELAY_US(us) __delay_cycles((F_CPU / 1000000) * (us)); // #define DELAY_MS(ms) __delay_cycles((F_CPU / 1000) * (ms)); /* */ // - UINT ADC_Result = 0; /* */ // void main( void ) { // // LED_INIT(); // LED_LOW(); // // ADC_IN_INIT(); // ADC_SET_CHAN(ADC7); ADC_ON(); // // 16 / 128 = 125 ADC_SET_CLK_DIV(ADC_F_CPU_DIV_128); // 50-200 // 13 125 13 / 125000 = 104 // for(;;) { // _NOP(); // LED_TOG(); // - ADC_START_CONV(); // - ? // (104 ) while(!ADC_RES_READY()); // _NOP(); // - ADC_Result = ADC; // //ADC_Result = ADCL; // //ADC_Result += (ADCH << 8); // // ADC_FLAG_CLEAR(); // 100 (1/0,1 = 10 - ) DELAY_MS(100); }//end for }//end main
/* */ #include <ioavr.h> #include <intrinsics.h> #include <ina90.h> /* */ // #define F_CPU 16000000 // #define UINT unsigned int /* */ // #define DELAY_US(us) __delay_cycles((F_CPU / 1000000) * (us)); // #define DELAY_MS(ms) __delay_cycles((F_CPU / 1000) * (ms)); /* */ // - UINT ADC_Result = 0; /* */ // void main( void ) { // // // 7- D DDRD_DDD7 = 1; // 7- D "0" PORTD_PORTD7 = 0; // // 7- A DDRA_DDA7 = 0; // PORTA_PORTA7 = 1; ADMUX_MUX0 = 1; // ADMUX_MUX1 = 1; ADMUX_MUX2 = 1; ADCSRA_ADEN = 1; // ADCSRA_ADPS0 = 1; // 16 / 128 = 125 ADCSRA_ADPS1 = 1; // 50-200 ADCSRA_ADPS2 = 1; // 13 125 13 / 125000 = 104 ADCSRA_ADIE = 1; // // _SEI(); // for(;;) { // _NOP(); // 7- D "0" "1" "1" "0" // PORTD_PORTD7 ^= 1; // - ADCSRA_ADSC = 1; // 100 (1/0,1 = 10 - ) DELAY_MS(100); }//end for }//end main /* -*/ #pragma vector=ADC_vect __interrupt void ISR_ADC(void) { // _NOP(); // - ADC_Result = ADC; // //ADC_Result = ADCL; // //ADC_Result += (ADCH << 8); // }//end func
/* */ #include <ioavr.h> #include <intrinsics.h> #include <ina90.h> /* */ // #define F_CPU 16000000 // #define UINT unsigned int // // #define LED_DDR DDRD #define LED_PORT PORTD #define LED_PIN DDD7 // #define ADC_IN_DDR DDRA #define ADC_IN_PORT PORTA #define ADC_IN_DDR_PIN DDA7 #define ADC_IN_PORT_PIN PORTA7 // #define ADC0 (0<<MUX2)|(0<<MUX1)|(0<<MUX0) #define ADC1 (0<<MUX2)|(0<<MUX1)|(1<<MUX0) #define ADC2 (0<<MUX2)|(1<<MUX1)|(0<<MUX0) #define ADC3 (0<<MUX2)|(1<<MUX1)|(1<<MUX0) #define ADC4 (1<<MUX2)|(0<<MUX1)|(0<<MUX0) #define ADC5 (1<<MUX2)|(0<<MUX1)|(1<<MUX0) #define ADC6 (1<<MUX2)|(1<<MUX1)|(0<<MUX0) #define ADC7 (1<<MUX2)|(1<<MUX1)|(1<<MUX0) // #define ADC_F_CPU_DIV_2 (0<<ADPS2)|(0<<ADPS1)|(1<<ADPS0) #define ADC_F_CPU_DIV_4 (0<<ADPS2)|(0<<ADPS1)|(1<<ADPS0) #define ADC_F_CPU_DIV_8 (0<<ADPS2)|(1<<ADPS1)|(0<<ADPS0) #define ADC_F_CPU_DIV_16 (0<<ADPS2)|(1<<ADPS1)|(1<<ADPS0) #define ADC_F_CPU_DIV_32 (1<<ADPS2)|(0<<ADPS1)|(0<<ADPS0) #define ADC_F_CPU_DIV_64 (1<<ADPS2)|(1<<ADPS1)|(0<<ADPS0) #define ADC_F_CPU_DIV_128 (1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0) /* */ // #define LED_INIT() ( LED_DDR |= (1<<LED_PIN) ); // #define LED_LOW() ( LED_PORT &=~ (1<<LED_PIN) ); // #define LED_HIGH() ( LED_PORT |= (1<<LED_PIN) ); // #define LED_TOG() ( LED_PORT ^= (1<<LED_PIN) ); // #define ADC_IN_INIT() ( ADC_IN_DDR &= ~(0<<ADC_IN_DDR_PIN) );\ ( ADC_IN_PORT |= (0<<ADC_IN_PORT_PIN) ); // #define ADC_SET_CHAN(x) ( ADMUX |= x ); // #define ADC_ON() ( ADCSRA |= (1<<ADEN) ); // #define ADC_OFF() ( ADCSRA &=~ (1<<ADEN) ); // #define ADC_SET_CLK_DIV(x) ( ADCSRA |= x ); // - #define ADC_START_CONV() ( ADCSRA |= (1<<ADSC) ); // #define ADC_INT_ON() ( ADCSRA |= (1<<ADIE) ); // #define DELAY_US(us) __delay_cycles((F_CPU / 1000000) * (us)); // #define DELAY_MS(ms) __delay_cycles((F_CPU / 1000) * (ms)); /* */ // - UINT ADC_Result = 0; /* */ // void main( void ) { // // LED_INIT(); // LED_LOW(); // // ADC_IN_INIT(); // ADC_SET_CHAN(ADC7); ADC_ON(); // // 16 / 128 = 125 ADC_SET_CLK_DIV(ADC_F_CPU_DIV_128); // 50-200 // 13 125 13 / 125000 = 104 ADC_INT_ON(); // // _SEI(); // for(;;) { // _NOP(); // LED_TOG(); // - ADC_START_CONV(); // 100 (1/0,1 = 10 - ) DELAY_MS(100); }//end for }//end main /* -*/ #pragma vector=ADC_vect __interrupt void ISR_ADC(void) { // _NOP(); // - ADC_Result = ADC; // //ADC_Result = ADCL; // //ADC_Result += (ADCH << 8); // }//end func
/* */ #include <ioavr.h> #include <intrinsics.h> #include <ina90.h> #include <stdbool.h> /* */ // #define F_CPU 16000000 // #define UCHAR unsigned char #define UINT unsigned int #define FLOAT_TYPE float // // #define LED_DDR DDRD #define LED_PORT PORTD #define LED_PIN DDD7 // #define F_CPU_DIV_1 (0<<CS02)|(0<<CS01)|(1<<CS00) #define F_CPU_DIV_8 (0<<CS02)|(1<<CS01)|(0<<CS00) #define F_CPU_DIV_64 (0<<CS02)|(1<<CS01)|(1<<CS00) #define F_CPU_DIV_256 (1<<CS02)|(0<<CS01)|(0<<CS00) #define F_CPU_DIV_1024 (1<<CS02)|(0<<CS01)|(1<<CS00) // #define TCNT0_VALUE 99 // #define T0_TICK_CNT_LIMIT 10 // #define ADC_IN_DDR DDRA #define ADC_IN_PORT PORTA #define ADC_IN_DDR_PIN DDA7 #define ADC_IN_PORT_PIN PORTA7 // #define ADC0 (0<<MUX2)|(0<<MUX1)|(0<<MUX0) #define ADC1 (0<<MUX2)|(0<<MUX1)|(1<<MUX0) #define ADC2 (0<<MUX2)|(1<<MUX1)|(0<<MUX0) #define ADC3 (0<<MUX2)|(1<<MUX1)|(1<<MUX0) #define ADC4 (1<<MUX2)|(0<<MUX1)|(0<<MUX0) #define ADC5 (1<<MUX2)|(0<<MUX1)|(1<<MUX0) #define ADC6 (1<<MUX2)|(1<<MUX1)|(0<<MUX0) #define ADC7 (1<<MUX2)|(1<<MUX1)|(1<<MUX0) // #define ADC_F_CPU_DIV_2 (0<<ADPS2)|(0<<ADPS1)|(1<<ADPS0) #define ADC_F_CPU_DIV_4 (0<<ADPS2)|(0<<ADPS1)|(1<<ADPS0) #define ADC_F_CPU_DIV_8 (0<<ADPS2)|(1<<ADPS1)|(0<<ADPS0) #define ADC_F_CPU_DIV_16 (0<<ADPS2)|(1<<ADPS1)|(1<<ADPS0) #define ADC_F_CPU_DIV_32 (1<<ADPS2)|(0<<ADPS1)|(0<<ADPS0) #define ADC_F_CPU_DIV_64 (1<<ADPS2)|(1<<ADPS1)|(0<<ADPS0) #define ADC_F_CPU_DIV_128 (1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0) // //0 #define SEG_0 ~(0x3f) //1 #define SEG_1 ~(0x06) //2 #define SEG_2 ~(0x5b) //3 #define SEG_3 ~(0x4F) //4 #define SEG_4 ~(0x66) //5 #define SEG_5 ~(0x6d) //6 #define SEG_6 ~(0x7d) //7 #define SEG_7 ~(0x07) //8 #define SEG_8 ~(0x7F) //9 #define SEG_9 ~(0x6F) //A #define SEG_A ~(0x77) //b #define SEG_b ~(0x7c) //C #define SEG_C ~(0x39) //d #define SEG_d ~(0x5e) //E #define SEG_E ~(0x79) //F #define SEG_F ~(0x71) // #define SEG_GRAD ~(0x63) // #define SEG_MASK (0x7F) // // // #define SEG_1DEC_PORT PORTD // #define SEG_2DEC_PORT PORTB // #define SEG_3DEC_PORT PORTA // #define SEG_1DEC_DDR DDRD // #define SEG_2DEC_DDR DDRB // #define SEG_3DEC_DDR DDRA /* */ // #define LED_INIT() ( LED_DDR |= (1<<LED_PIN) ); // #define LED_LOW() ( LED_PORT &=~ (1<<LED_PIN) ); // #define LED_HIGH() ( LED_PORT |= (1<<LED_PIN) ); // #define LED_TOG() ( LED_PORT ^= (1<<LED_PIN) ); // #define TIMER0_SET_CLK_DIV(x) ( TCCR0 |= x ); // #define TIMER0_SET_CNT(x) ( TCNT0 = x ); // #define TIMER0_OVF_INT_ON() ( TIMSK|=(1<<TOIE0) ); // #define ADC_IN_INIT() ( ADC_IN_DDR &= ~(0<<ADC_IN_DDR_PIN) );\ ( ADC_IN_PORT &= ~(0<<ADC_IN_PORT_PIN) ); // #define ADC_SET_CHAN(x) ( ADMUX |= x ); // #define ADC_ON() ( ADCSRA |= (1<<ADEN) ); // #define ADC_OFF() ( ADCSRA &=~ (1<<ADEN) ); // #define ADC_SET_CLK_DIV(x) ( ADCSRA |= x ); // - #define ADC_START_CONV() ( ADCSRA |= (1<<ADSC) ); // #define ADC_INT_ON() ( ADCSRA |= (1<<ADIE) ); // #define SEG_PORTS_INIT() ( SEG_3DEC_DDR |= SEG_MASK );\ ( SEG_2DEC_DDR |= SEG_MASK );\ ( SEG_1DEC_DDR |= SEG_MASK ); // #define SEG_PORTS_CLEAR() ( SEG_3DEC_PORT &=~ SEG_MASK );\ ( SEG_2DEC_PORT &=~ SEG_MASK );\ ( SEG_1DEC_PORT &=~ SEG_MASK ); // #define SEG_PORTS_OUT(x,y,z) ( SEG_3DEC_PORT |= ( x & SEG_MASK ) );\ ( SEG_2DEC_PORT |= ( y & SEG_MASK ) );\ ( SEG_1DEC_PORT |= ( z & SEG_MASK ) ); // #define DELAY_US(us) __delay_cycles((F_CPU / 1000000) * (us)); // #define DELAY_MS(ms) __delay_cycles((F_CPU / 1000) * (ms)); /* */ // T0 UINT T0_tick_cnt=0; // const unsigned char numbers[16] = { SEG_0, //0 SEG_1, //1 SEG_2, //2 SEG_3, //3 SEG_4, //4 SEG_5, //5 SEG_6, //6 SEG_7, //7 SEG_8, //8 SEG_9, //9 SEG_A, //A SEG_b, //b SEG_C, //C SEG_d, //d SEG_E, //E SEG_F //F }; // FLOAT_TYPE T = 0; // - UINT ADC_Result = 0; // - - UINT ADC_res_cnt = 0; // UINT Sum = 0; // - bool ADCReadyFlag = false; /* ** Name: Seg_Write() ** Description: ** ** Parameters: UINT T - 0 - 99 C ** Returns: none */ void Seg_Write(UINT T) { // UINT dec2 = 0 , dec1 = 0; // T = T % 100; // dec2 = T / 10; // dec1 = T % 10; // // SEG_PORTS_CLEAR(); // 3- // // SEG_PORTS_OUT( numbers[dec2], // numbers[dec1], // SEG_GRAD // ); }//end func /* ** Name: main() ** Description: , ** Parameters: none ** Returns: none */ // void main( void ) { // // SEG_PORTS_INIT(); // LED_INIT(); // LED_LOW(); // ( Normal) TIMER0_SET_CLK_DIV(F_CPU_DIV_1024);// 16 000 000 // 16 000 000 / 1024 = 15 625 // 1 / 15 625 = 0,000064 =64 TIMER0_SET_CNT(TCNT0_VALUE); // 156 * 0,000064 c = 0,009984 c (10 ) // 255-156 = 99 TIMER0_OVF_INT_ON(); // // // ADC_IN_INIT(); // ADC_SET_CHAN(ADC7); ADC_ON(); // // 16 / 128 = 125 ADC_SET_CLK_DIV(ADC_F_CPU_DIV_128); // 50-200 // 13 125 13 / 125000 = 104 ADC_INT_ON(); // // T=0; // Sum = 0; // _SEI(); // for(;;) { // _NOP(); // - // if(ADCReadyFlag) { // _NOP(); // ADCReadyFlag = false; // LED_TOG(); // //- Sum += ADC_Result; // //- ADC_res_cnt++; // -? if ( ADC_res_cnt == 8 ) { // _NOP(); // ADC_res_cnt = 0; // ADC_Result = Sum / 8; // Sum = 0; // T = ADC_Result*(5.0/1023); // T = ((T-0.75)*100)+25; // // Seg_Write((UINT)T); }//end if }//end if }//end for }//end main /* T0 */ #pragma vector=TIMER0_OVF_vect __interrupt void ISR_TickTimer(void) { // _NOP(); // T0 T0_tick_cnt++; // 100 if (T0_tick_cnt >= T0_TICK_CNT_LIMIT) { // _NOP(); // T0 T0_tick_cnt=0; // // - ADC_START_CONV(); }//end for // // TIMER0_SET_CNT(TCNT0_VALUE); }//end func /* -*/ #pragma vector=ADC_vect __interrupt void ISR_ADC(void) { // _NOP(); // - ADC_Result = ADC; // //ADC_Result = ADCL; // //ADC_Result += (ADCH << 8); // // - ADCReadyFlag = true; }//end func
Source: https://habr.com/ru/post/226539/
All Articles