This is a sample final report about automotive electrical and electronic engineering subject in HCMs university of technology and education. This is necessary for first and second student who do the final electronic reporttation.
Trang 1MINISTRY OF EDUCATION AND TRAINING
HCMC UNIVERSITY OF TECHNOLOGY AND EDUCATION
FACULTY FOR HIGH QUALITY TRAINING
Trang 2printf("Hello everyone! \n");
return 0;
}
2.2.Homework page 20.
Trang 3#include <stdio.h>
//hw p20/* global variable declaration*/
int g;
int main (){/*global variable declaration*/
Trang 42.3.Homework page 23.
#include <stdio.h>
main (){int a = 21;
Trang 52.4Homework page 25.
#include <stdio.h>
main(){int a=21;
int b=10;
int c;
if ( a == b ){printf ("line 1 - a is equal to b\n");
}else{printf ("line 1 - a is not equal to b\n");
}
if ( a < b ){printf("line 2- a is less than b\n");
}else{printf("line 2 - a is not less than b\n");
}
Trang 6if ( a > b ){printf("line 3 - a is greater than b\n");
}else{printf("line 3 - a is not greater than b\n");
}/* Lets change value of a and b*/
a=5;
b=20;
if ( a <= b ){printf("line 4 - a is either less than or equal to b\n");
}
if ( b >= a ){printf("line 5 - a is either greater or equal to b\n");
}}
Trang 72.5Homework page 27.
#include <stdio.h>
main (){int a = 5;
int b = 20;
int c;
if ( a && b )
{printf("line 1 - condition is true\n");
}
if ( a || b ){printf("line 2 - conditon is true\n");
}
Trang 8/*Lets change the value of a and b*/
a=0;
b=10;
if ( a && b )
{printf("line 3 - condition is true\n");
}else{printf("line 3 - condition is not true\n");
}
if ( !(a && b) )
{printf ("line 4 - condition is true\n");
}}
2.6Homework page 30.
#include <stdio.h>
main (){unsigned int a = 60; /* 60 = 0011 1100 */unsigned int b = 13; /* 13 = 0001 1101 */
Trang 9int c = 0;
c = a & b; /* 12= 0000 1100 */printf ( "line 1 - value of c is %d\n", c);
c = a || b; /* 61= 0011 1101 */printf ("line 2 - value of c is %d\n", c);
c = a ^ b; /* 49= 0011 0001*/printf ("libe 3 - value of c is %d\n",c);
c =~ a; /* -61= 1100 0011*/printf("line 4 - value of c is %d\n",c);
c = a << 2; /* 240= 1111 0000*/printf ("line 5 - value of c is %d\n",c);
c = a >> 2; /* 15= 0000 1111*/printf ("line 6 - value of c is %d\n",c);
}
2.7.Homework page 33.
#include <stdio.h>
main(){int a = 21;
int c ;
Trang 11printf("Line 11 - |= Operator Example, Value of c = %d\n", c );
}
2.8.Homework page 35.
#include <stdio.h>
main(){int a = 20;
e = ((a + b) * c) / d; // (30 * 15 ) / 5printf("Value of ((a + b) * c) / d is : %d\n" , e );
e = (a +b) * (c / d); // (30) * (15/5)printf("Value of (a + b) * (c / d) is : %d\n", e);
e = a + (b * c) / d; // 20 + (150/5)
Trang 12int a = 10;
/* check the boolean condition using if statement */
if( a < 20){
/* if condition is true then print the following */
printf ("a is less than 20\n");
}printf("value of a is : %d\n", a);
Trang 13int a = 100;
/* check the boolean condition */
if( a == 10 ){
/* if condition is the true then print the following */
printf("value of a is 10\n" );
}else if( a == 20 )
{/* if else if condition is true */
Trang 14printf("value of a is 20\n");
}else if( a == 30 )
{/* if else if condition is true */
printf("value of a is 30\n");
}else{/* if none of the conditions is true */printf("None of the values is matching\n");
}printf("Exact value of a is: %d\n", a );
Trang 15{/* local variable definition */
char grade = 'B';
switch(grade)
{case 'A' :printf("Excellent!\n" );
break;
case 'B' :case 'C' :printf("Well done\n" );
break;
case 'D' :printf("You pased\n" );
break;
case 'F' :printf("Better try again\n" );
break;
default :printf("Invalid grade\n" );
}printf("Your grade is %c\n", grade );
return 0;
}
Trang 162.12.Homework page 49.
#include <stdio.h>
int main ()
{ /* global variable definition*/
int a=10;
/* while loop excution*/ while (a<20)
{ printf( "value of a: %d\n",a);
a++;
} }
Trang 17a = a + 1;
}while (a<20);
return 0;
}
Trang 19int max (int num1, int num2)/*function returning the max between two numbers*/
{/*local variable definition*/
int result;
if(num1 > num2)result=num1;
elseresult=num2;
return result;
}
3.Moving led, traffic light, seven-segment LED and ADC
on LCD :
Trang 20Code: #include <mega32a.h>
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 conversionADCSRA|=0x40;
Trang 21// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
}void hienthi_thapphan(unsigned char so)
{lcd_putchar(so/10%10 + 48); //chuc
lcd_putsf(".");
lcd_putchar(so%10 + 48); //donvi
lcd_putsf("V");
}interrupt [EXT_INT0] void ext_int0_isr(void)
{PORTA.2=1;
Trang 23}void main(void)
{DDRA = 0b11111100;
// ADC initialization
// ADC Clock frequency: 250 kHz// ADC Voltage Reference: AVCC pinADMUX=ADC_VREF_TYPE & 0xff;ADCSRA=0x82; // cho phep chuyen doi
while (1){ADC0 = read_adc(0);
Trang 24}PORTC.3=0;
delay_ms(50);
PORTB.1=1;
for (i=2;i>=0;i )
{PORTD =LED7_Code[i];
delay_ms(100);
}PORTB.1=0;
delay_ms(50);
PORTB.0=1;
for (i=9;i>=0;i )
{PORTD =LED7_Code[i];
delay_ms(100);
Trang 25PORTB.0=0;delay_ms(50);
}
}
1.Moving led
Trang 261 7 Segment LED
Trang 282 LCD