a4arijit
Newbie level 6

Hi,
Once again I'm back with my stupidity..I'm working on a project that process an ADC data and transmit them to the PC using a DB9 COM port.For that I need the USART working.For testing purposes I'm using HyperTerminal 7 .I came up with a program (its worse enough to laugh) but its highly predictable that I failed..Can anyone put me out of my misery??I'm posting the code below..Please help me..
Code ::
Once again I'm back with my stupidity..I'm working on a project that process an ADC data and transmit them to the PC using a DB9 COM port.For that I need the USART working.For testing purposes I'm using HyperTerminal 7 .I came up with a program (its worse enough to laugh) but its highly predictable that I failed..Can anyone put me out of my misery??I'm posting the code below..Please help me..
Code ::
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 /************************************************** *** This program was produced by the CodeWizardAVR V2.03.4 Standard Automatic Program Generator © Copyright 1998-2008 Pavel Haiduc, HP InfoTech s.r.l. HP InfoTech, Development Tools for Microcontrollers, C Compilers, In-System Programmers Project : Version : Date : 6/27/2011 Author : Company : Comments: Chip type : ATmega16 Program type : Application Clock frequency : 16.000000 MHz Memory model : Small External RAM size : 0 Data Stack size : 256 ************************************************** ***/ #include <mega16.h> // Standard Input/Output functions #include <stdio.h> #include <delay.h> #include <math.h> #define ADC_VREF_TYPE 0x00 float temperature; float temperaturee; unsigned int temporary; void updatetemp(void); void sett_regs(void); unsigned int read_adc(unsigned char adc_input); // Main function void main(void) { //--------------- Setting IO and peripheral at startup! sett_regs(); //--------------- Time for going CRAZY (looping forever).. for(;;) { //mainloop looping forever until ERROR/POWER SHUTDOWN/RST/WDT ACTIVE #asm("wdr") //kick your DOG before DEAD! hwahwa... :D updatetemp(); #asm("nop") }; } void updatetemp(void) { if (temporary != read_adc(1)) { temperature = read_adc(1)/2.007; temperaturee = ((9*temperature)/5)+32; temporary = read_adc(1); delay_ms(100); } } // Read the AD conversion result unsigned int read_adc(unsigned char adc_input) { ADMUX=adc_input | (ADC_VREF_TYPE & 0xff); // Delay needed for the stabilization of the ADC input voltage delay_us(10); // Start the AD conversion ADCSRA|=0x40; // Wait for the AD conversion to complete while ((ADCSRA & 0x10)==0); ADCSRA|=0x10; return ADCW; } // Declare your global variables here void sett_regs(void) { // Declare your local variables here // Input/Output Ports initialization // Port A initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTA=0x00; DDRA=0x00; // Port B initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTB=0x00; DDRB=0x00; // Port C initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTC=0x00; DDRC=0x00; // Port D initialization // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T PORTD=0x00; DDRD=0x00; // Timer/Counter 0 initialization // Clock source: System Clock // Clock value: Timer 0 Stopped // Mode: Normal top=FFh // OC0 output: Disconnected TCCR0=0x00; TCNT0=0x00; OCR0=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 // Timer 1 Overflow Interrupt: Off // Input Capture Interrupt: Off // Compare A Match Interrupt: Off // Compare B Match Interrupt: Off TCCR1A=0x00; TCCR1B=0x00; TCNT1H=0x00; TCNT1L=0x00; ICR1H=0x00; ICR1L=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 // INT2: Off MCUCR=0x00; MCUCSR=0x00; // Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x00; // USART initialization // Communication Parameters: 8 Data, 1 Stop, No Parity // USART Receiver: On // USART Transmitter: On // USART Mode: Asynchronous // USART Baud Rate: 9600 UCSRA=0x00; UCSRB=0x18; UCSRC=0x86; UBRRH=0x00; UBRRL=0x67; // Watchdog Timer initialization // Watchdog Timer Prescaler: OSC/2048k #pragma optsize- WDTCR=0x1F; WDTCR=0x0F; #ifdef _OPTIMIZE_SIZE_ #pragma optsize+ #endif // Analog Comparator initialization // Analog Comparator: Off // Analog Comparator Input Capture by Timer/Counter 1: Off ACSR=0x80; SFIOR=0x00; // ADC initialization // ADC Clock frequency: 250.000 kHz // ADC Voltage Reference: AREF pin // ADC Auto Trigger Source: None ADMUX=ADC_VREF_TYPE & 0xff; ADCSRA=0x86; while(1) { temperature =getchar(); putchar (temperature); } }
Last edited: