首页
服务项目
代写案例
服务流程
客户好评
联系我们
data编程代写、代做C++,Python程序
1.Project Temperature Controlled Fan
The temperature controlled fan activates or turn off a fan determined by the ambient temperature. Refer to the appendix for the circuit.
Figure 1-1
2.Code Development Part 1
2.1I/O Initialisation
Create the I/O initialization routine.
Refer to the schematic to determine which are the I/O that are inputs and outputs using the DDRx registers. Digital input ports must be set to logic ‘0’.
For I/O that are analog, their digital function must be disabled using the DIDRO register. Their logic needs to be set to ‘0’. void ioInit(){
DDRB =
DDRC =
DDRD =
PORTB =
PORTC =
PORTD =
DIDR0 =
}
Listing 2-1
2.2 3-Digit Display
The concept of driving the 3-digit multiplexing display is shown in Figure 2-1.
A timer interrupt determines the rate of multiplexing. The displayNow( ) is call whenever the timer interrupt. The global variable dpNum stores the 3-digit number to be displayed. The global variable whichDigit determines which digit to turn on. Example, if whichDigit is “2” and dpNum is “295”. The displayNow( ) function when called, will display “9” on the 2nd digit (display the 10th). The displayNow( ) function also maintains the content inside whichDigit to between 1 to 3.
Listing 2-2 shows an example of how the displayNow( ) function can be written.
unsigned int dpNum; // Declare these 2 variables as global.
unsigned char whichDigit;
void displayNow(){
PORTB = // Turn off all mux transistors.
PORTC = // Clear the 4 bit BCD output ports to 0.
switch(whichDigit){
case 1: PORTC = (PORTC & 0xF0) | (dpNum/100);// Display 100th.
PORTB = (PORTB & 0xF8) | 0x01 // Turn on mux 1 transistor.
break;
case 2: // Complete case 2 & 3.
case 3:
}
whichDigit++; // Setup for next digit.
if (whichDigit>3) whichDigit = 1; // Set back to 1st digit.
}
Listing 2-2
2.3 Timer 0 Interrupt
Program timer 0 to interrupt at an interval of 5ms. The displayNow( ) function is called every interrupt. This will take care of the multiplexing display of the content in variable displayNumber.
void interruptInit(){
// Run timer 0 with prescaler 1024.
TCCR0B =
// Enable timer 0 interrupt.
TIMSK0 =
}
ISR(TIMER0_OVF_vect) {
// Load timer for 5 ms overflow.
TCNT0 =
displayNow();
}
Listing 2-3
2.4 Test Your Multiplexing Display
Test your program. You should see the 3-digit LED display showing the number in the variable displayNumber. #include
#include
// Declare your global variables here.
// Place all supporting functions here.
int main(){
ioInit();
interruptInit();
// Place the Global Interrupt enable
// instruction here.
while(1){
// Nothing need to be done
// in this while-loop.
}
Listing 2-4
3.Code Development Part 2
3.1 ADC
Create 2 functions: (1) readADC( ) and (2) initADC( ). Merge this program with the codes you have developed in Code Development Part 1. Test your ADC acquisition by reading the temperature sensor into a variable (tempInADC) and pass the content to the variable dpNum. The content in the dpNum variable will be displayed on the 3-digit LED display. Note that the display number is the ADC value and not the temperature.
unsigned int readADC(){
// Select ADC channel to read.
ADMUX =
// Start ADC conversion.
ADCSRA =
// Wait for ADC conversion complete.
- - - -
// Reset ADC complete flag.
- - - -
// Return converted value.
- - - -
}
void initADC(){
// Enable ADC, clear ADC conversion flag
// & set ADC clock.
ADCSRA =
// Set up reference voltage.
ADMUX =
}
int main(){
- - - -
// Merge with the codes in Listing 2-4.
- - - -
- - - -
initADC();
while(1){
tempInADC = readADC();
dpNum = tempInADC;
}
}
Listing 3-1
3.2 Convert ADC Reading to Temperature
Modify the program in Listing 3-1 to display temperature instead of ADC value. Add a conversion function to convert the temperature in ADC value to oC before passing the data to dpNum for display. If your hardware is capable of displaying the decimal point, you should program it.
unsigned int readADC(){
- - - - -
- - - - -
}
unsigned int convert(unsigned int k){
// Perform the conversion of ADC value
// to temperature value here and store
// the final value in temperature.
return(temperature);
}
int main(){
- - - -
- - - -
while(1){
tempInADC = readADC();
dpNum = convert(tempInADC);
}
}
Listing 3-2
4.Code Development Part 3
4.1 Activating the Fan
Define the temperature to turn on and off the fan. In the main( ) function, use decision making instruction such as if-statement to decide when to turn on or off the fan.
#include
#include
#define TurnOnTemp 260
#define TurnOffemp 250 int main(){
- - - -
- - - -
while(1){
tempInADC = readADC();
dpNum = convert(tempInADC);
// If temperature greater or equal
// TurnOnTemp, activate the fan.
// If temoerature less or equal to
// TurnOffTemp, off the fan.
}
}
Listing 4-1
5.Additional Features
Notice that the following resources on the circuit*1 which are not used in the above coding:
1.Potentiometer, VR1
2.LED. D2
3.A set of pusb buttons, SW1 to SW3
What other features can you add to your “product”?
*1 Referring to the project circuit. If you are using the trainer circuit, the resources are different.
Appendix A: Project Board Schematic
Appendix B: Trainer Schematic
END OF PAPER
热门主题
代做ceng0006: coursework代写...
02-22
代做assignment 1 - case stud...
02-22
代写co 101 project 1 mass co...
02-22
代做uestc 4004 digital commu...
02-22
代做accfin5246 data science ...
02-22
代写accfin5246_2a data scien...
02-22
代做java lab 2代做留学生java...
02-22
代写math 132a assignment 4代...
02-22
代做uestc 4004 digital commu...
02-22
代做uestc 4004 digital commu...
02-22
代写math 132a assignment 3调...
02-22
代做uestc 4004 digital commu...
02-22
代写ee6307、代做java/python编...
02-22
代写program、代做python设计编...
02-22
代写tutorial 5 structured qu...
02-21
代写homework 6: measuring bi...
02-21
代做problem set 1代写process...
02-21
代写f24 adms 3541 case study...
02-21
代写lang7402 introduction to...
02-21
代写english language and stu...
02-21
课程名
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
站长地图