This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main(void) { | |
unsigned long side; // Chiều dài của phòng đơn vị mét | |
unsigned long area; // Diện tích phòng đơn vị mét vuông | |
UART_Init(); // gọi subroutine để init uart | |
printf("This program calculates areas of square-shaped rooms\n"); | |
for(side = 1; side < 50; side = side+1){ | |
area = Calc_Area(side); | |
printf("\nArea of the room with side of %ld m is %ld sqr m\n",side,area); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned long error; | |
// Tính diện tích căn phòng | |
// Input: kích thước căn phòng (unsigned long) | |
// Output: diện tích căn phòng (unsigned long) | |
// Notes: ... | |
unsigned long Calc_Area(unsigned long s) { | |
unsigned long result; | |
if(s <= 25){ | |
result = s*s; | |
}else{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Tính diện tích căn phòng hình vuông | |
// Input: Kích thước căn phòng (kiểu unsigned long) đơn vị mét | |
// Output: Diện tích căn phòng (kiểu unsigned long) đơn vị mét vuông | |
unsigned long Calc_Area(unsigned long s) { | |
unsigned long result; | |
result = s*s; | |
return(result); | |
} | |
int main(void) { | |
unsigned long side; // Kích thước căn phòng |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned long Calc_Area(unsigned long s); | |
int main(void) { | |
unsigned long side; // độ dài bức tường đơn vị met | |
unsigned long area; // diện tích căn phòng đơn vị met vuông | |
UART_Init(); // gọi subroutine để init uart | |
printf("This program calculates areas of square-shaped rooms\n"); | |
side = 3; | |
area = Calc_Area(side); | |
printf("\nArea of the room with side of %ld m is %ld sqr m\n",side,area); | |
side = side+2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main(void){ | |
long x,y,z; // 3 biến x y z là local variables | |
x=1; y=2; // set giá trị của x và y | |
z = x+4*y; // tính z | |
x++; // Tăng x, cái này giống x=x+1; | |
y--; // Tương tự giảm y, giống y=y-1; | |
x = y<<2; // Dịch trái, tương tự x=4*y; | |
z = y>>2; // Dịch phải, tương tự x=y/4; | |
y += 2; // Tăng y, tương tự y=y+2; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "tm4c123ge6pm.h" | |
unsigned long In; // input from PF4 | |
unsigned long Out; // output to PF2 (blue LED) | |
// Function Prototypes | |
void PortF_Init(void); | |
// 3. Subroutines Section |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 0.Documentation Section | |
// main.c | |
// Runs on LM4F120 or TM4C123 | |
// C6_InputOutput, Input from PF4, output to PF2 (blue LED) | |
// Authors: Daniel Valvano, Jonathan Valvano and Ramesh Yerraballi | |
// Date: July 8, 2013 | |
// LaunchPad built-in hardware | |
// SW1 left switch is negative logic PF4 on the Launchpad | |
// SW2 right switch is negative logic PF0 on the Launchpad |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Chương trình đọc nhiệt độ, độ ẩm từ cảm biến DHT | |
// Written by ladyada, public domain | |
// Chỉnh sửa cho ESP8266 bởi hocARM.org | |
#include "DHT.h" | |
#define DHTPIN D1 // Chân DATA nối với chân D1 | |
// Uncomment loại cảm biến bạn sử dụng, nếu DHT11 thì uncomment DHT11 và comment DHT22 | |
#define DHTTYPE DHT11 // DHT 11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while(side != 0){ | |
printf("Give room side(zero to quit):"); | |
scanf("%ld", &side); | |
area = Calc_Area(side); | |
if(area != 0){ | |
printf("\nArea with side of %ld m is %ld sqr m\n",side,area); | |
} else { | |
printf("\n Size cannot exceed 25 meters\n"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main(void) { | |
unsigned long side; // room wall meters | |
unsigned long area; // size squared meters | |
UART_Init(); // call subroutine to initialize the uart | |
printf("This program calculates areas of square-shaped rooms\n"); | |
side = 1; | |
while(side < 50){ | |
area = Calc_Area(side); | |
printf("\nArea of the room with side of %ld m is %ld sqr m\n",side,area); | |
side = side+1; |