Execute
Save
Share
Share link
share
share
share
Team
Public Teams
Comments
0
Created By:
Guest
Title:
Title
Description
Edit
Copy Link
Login
Email *
Password *
Login
OR
Create Account
Screen Name *
Email *
Password *
Retype Password *
Team Access Code
Register
Public CodeBins
HELP
--Select Theme--
Ambiance
Blackboard
Cobalt
Eclipse
Elegant
Erlang-Dark
Lesser-Dark
Monokai
Neat
Night
Rubyblue
Vibrant-Ink
Xq-Dark
New CodeBin
CodeBins Versions
06/04/2017- V.3
06/04/2017- V.2
06/04/2017- V.1
Compare Versions
Recent CodeBins
View All CodeBins
Bottom of Page
In Head
On Load
On Ready
Setting
Validate
Copy
Format
/***** Project Header *****/ // Project Name: // Author: // Date: 21/10/2016 14:51 // Code auto-generated by systemdesignerjs // from www.techideas.co.nz /***** Hardware defines *****/ //make sure this matches your oscillator setting #define F_CPU 16000000//crystal /***** Includes *****/ #include <avr/io.h> //#include <stdint.h> #include <util/delay.h> //#include <avr/interrupt.h> //#include <avr/eeprom.h> //#include <stdio.h> //#include <string.h> //#include <avr/pgmspace.h> /***** Hardware macros *****/ //Hardware macros for outputs #define SET_FAN PORTB |= (1<<PB3) #define CLR_FAN PORTB &= ~(1<<PB3) //Hardware macros for inputs //Hardware macros for ADC inputs #define TEMPR_SENSOR 1 //macro to refer to ADC channel /***** User macros *****/ #define READING_INTERVAL 5000 //5 seconds #define VREF 1.1 #define MAX_ADC 255 #define RATE 100.0 #define MAX_FAN 69 #define MIN_FAN 54 /***** Declare & initialise global variables *****/ /***** Interrupt Service Routines *****/ /***** Prototypes for Functions *****/ uint8_t get_tempr(uint16_t adc_reading); void control_fan(uint8_t tempr); /***** Configure ADC *****/ void init_ADC() { //At 16MHZ set prescaler to 128 to get 125Khz clock ADCSRA |= ((1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0)); //At 8MHz set prescaler to 64 to get 125Khz clock //ADCSRA |= ((1<<ADPS2)|(1<<ADPS1)); //At 1MHz set prescaler to 8 to get 125Khz clock //ADCSRA |= ((1<<ADPS1)|(1<<ADPS0)); //AVcc as voltage reference with external capacitor on ARef ADMUX |= (1<<REFS1); //uncomment this line for internal voltage ADMUX |= (1 << REFS0); ADCSRA |= (1 << ADEN); //Power on the ADC ADCSRA |= (1 << ADSC); //Start initial conversion } // get a single adc reading from one channel uint16_t read_adc(uint8_t channel) { ADMUX &= 0xF0; //Clear previously read channel ADMUX |= channel; //Set to new channel to read ADCSRA |= (1 << ADSC); //Starts a new conversion while (ADCSRA & (1 << ADSC)); //Wait until the conversion is done return ADCW; //Returns the value from the channel } /***** Main function *****/ int main(void) { /***** Initial hardware setups go here *****/ init_ADC(); //setup the ADC to work /***** IO Hardware Config *****/ // Initially make all micro pins outputs DDRB = 0xff; //set as outputs DDRC = 0xff; //set as outputs DDRD = 0xff; //set as outputs // make these pins inputs DDRC &= ~ (1 << PC1); /***** Main variables go here *****/ uint8_t tempr = 0; uint16_t tempr_sensor_val = 0; /***** Run once code goes here *****/ /***** Loop code *****/ while (1) { //DO NOT CHANGE THESE LINES OF CODE tempr_sensor_val = read_adc(1); // TEMPR_SENSOR_ tempr = get_tempr(tempr_sensor_val); control_fan(tempr); _delay_ms(5000); // READING_INTERVAL_ } //while end } //main end /***** Functions *****/ uint8_t get_tempr(uint16_t adc_reading) { uint16_t read = (1.1 * adc_reading) / (255 / 100.0); // RATE_ MAX_ADC_ VREF_ return read; // RATE_ MAX_ADC_ VREF_ return ((int)adc_reading*(int)1.1)/((int)255/(int)100.0); // ADD CODE HERE to convert the adc readng from the LM35 to degrees C // you must use only integer math and return an 8 bit unsigned value // the variable tempr must return the correct value from 0 to 99 degrees } void control_fan(uint8_t tempr) { if (tempr > 69) { // MAX_FAN_ PORTB |= (1<<PB3); // SET_FAN_ SET_FAN_ } if (tempr < 54) { // MIN_FAN_ PORTB &= ~(1<<PB3); // CLR_FAN_ } //ADD CODE HERE TO CONTROL THE FAN }
Setting
Validate
Copy
Format
No Doc Type
HTML5
HTML 4.01 Transitional
HTML 4.01 Strict
HTML 4.01 Frameset
XHTML 1.1
XHTML 1.0 Transitional
XHTML 1.0 Strict
XHTML 1.0 Frameset
Copy
Format
Download
×
Code Description
×
Difference of Versions
HTML
CSS
JS
×
JS Error
×
CSS Error
Errors
Warnings
×
JavaScript Setting
JS Libraries:
Chrome Frame 1.0.3
Dojo 1.8.0
Dojo 1.7.3
Dojo 1.7.2
Ext Core 3.1.0
jQuery 1.8.0
jQuery 1.7.2
jQuery 1.6.0
jQuery 1.5.0
jQuery 1.4.4
jQuery 1.4.0
jQuery-min 1.7.2
jQueryUI-min 1.8.21
MooTools more-1.4.0.1-full
MooTools core-1.4.5-full
MooTools core-1.4.1-full
Prototype 1.7.1.0
script.aculo.us 1.9.0
SWFObject 2.2
Twitter Bootstrap 2.0.4
WebFont Loader 1.0.28
yui 3.5.1
User Libraries:
Upload File
JavaScript URL(s):
×
CSS Setting
CSS Libraries:
jQueryUI 1.8.21
Twitter Bootstrap 2.0.4
User Libraries:
Upload File
CSS URL(s):