1. Trang chủ
  2. » Giáo Dục - Đào Tạo

Báo cáo đồ án kỹ thuật vi xử ly

19 16 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Báo Cáo Đồ Án Kỹ Thuật Vi Xử Lý
Trường học Trường Đại Học Cần Thơ
Chuyên ngành Kỹ Thuật Vi Xử Lý
Thể loại báo cáo đồ án
Năm xuất bản 2023
Thành phố Cần Thơ
Định dạng
Số trang 19
Dung lượng 305,19 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

TRƯỜNG ĐẠI HỌC CẦN THƠ TRƯỜNG BÁCH KHOA BÁO CÁO ĐỒ ÁN KỸ THUẬT VI XỬ LÝ ĐỀ TÀI : XXXXX GIẢNG VIÊN HƯỚNG DẪN: SINH VIÊN THỰC HIỆN: Cần Thơ, ngày xx tháng xx Năm 2023...  Module cảm bi

Trang 1

TRƯỜNG ĐẠI HỌC CẦN THƠ TRƯỜNG BÁCH KHOA

BÁO CÁO ĐỒ ÁN KỸ THUẬT VI XỬ LÝ

ĐỀ TÀI : XXXXX

GIẢNG VIÊN HƯỚNG DẪN: SINH VIÊN THỰC HIỆN:

Cần Thơ, ngày xx tháng xx Năm 2023

Trang 2

3.1 Sơ đồ khối:

Lựa chọn linh kiện :

 Bộ xử lí trung tâm: MSP430G2553 (3.3V)

 LCD 16x2

 Cảm biến nhiệt độ ngõ ra analog LM35 (5V)

 Module cảm biến khí gas ngõ ra digital MQ2 (5V)

 Biến trở 10kΩ

 Led đơn

 Điện trở: 220Ω, 4,7kΩ

 Nút nhấn

3.2 Sơ đồ nguyên lí:

1

Trang 3

3.3 Lưu đồ thuật toán:

Trang 5

3.4 Code chương trình:

#include "msp430g2553.h"

#include "intrinsics.h"

#include "string.h"

#include "stdio.h"

#include "UART.h"

// -union reg {

struct bit {

unsigned char b0:1;

unsigned char b1:1;

unsigned char b2:1;

unsigned char b3:1;

unsigned char b4:1;

unsigned char b5:1;

unsigned char b6:1;

unsigned char b7:1;

}_BIT;

unsigned char _BYTE;

};

union reg* P2_DIR=(union reg*)0x2a; //khai bao dia chi o nho

union reg* P2_OUT=(union reg*)0x29;

union reg* P2_SEL=(union reg*)0x2e;

union reg* P2_IN=(union reg*)0x28;

union reg* P1_SEL=(union reg*)0x26;

union reg* P1_DIR=(union reg*)0x22; //khai bao dia chi o nho

union reg* P1_OUT=(union reg*)0x21;

union reg* P1_IN=(union reg*)0x20;

//

===========================================================

=========================================================== //

===========================================================

===================

//DINH NGHIA LCD:

#define MCLK_F 1 // frequency of Master Clock in MHz

Trang 6

******************************************************************

**********

* HARD DEFINITIONS

******************************************************************

************/

/* Display ON/OFF Control definitions */

#define DON 0x0F /* Display on */

#define DOFF 0x0B /* Display off */

#define CURSOR_ON 0x0F /* Cursor on */

#define CURSOR_OFF 0x0D /* Cursor off */

#define BLINK_ON 0x0F /* Cursor Blink */

#define BLINK_OFF 0x0E /* Cursor No Blink */

/* Cursor or Display Shift definitions */

#define SHIFT_CUR_LEFT 0x04 /* Cursor shifts to the left */

#define SHIFT_CUR_RIGHT 0x05 /* Cursor shifts to the right */

#define SHIFT_DISP_LEFT 0x06 /* Display shifts to the left */

#define SHIFT_DISP_RIGHT 0x07 /* Display shifts to the right */

/* Function Set definitions */

#define FOUR_BIT 0x2C /* 4-bit Interface */

#define EIGHT_BIT 0x3C /* 8-bit Interface */

#define LINE_5X7 0x30 /* 5x7 characters, single line */

#define LINE_5X10 0x34 /* 5x10 characters */

#define LINES_5X7 0x38 /* 5x7 characters, multiple line */

//

===========================================================

===

// Your YM1602C 16x2 must be supplied with a voltage between 4.5V-5.5V

// However, signal pins can understand 3.3V logic level from MSP430 as '1'

// Check your hardware connecting and map it to these definitions below

// Map: LCD PIN <-> Output_Port _ out/dir -> Output_Pin

#define LCD_RS P2_OUT -> _BIT.b0

#define LCD_RS_DIR P2_DIR -> _BIT.b0

#define LCD_EN P2_OUT -> _BIT.b1

#define LCD_EN_DIR P2_DIR -> _BIT.b1

// This driver just help you to "write" LCD, not to read LCD "status"

// So that, you must pull your pin LCD_RW to GND (0V)

#define LCD_DATA_4 P2_OUT -> _BIT.b2

5

Trang 7

#define LCD_DATA_4_DIR P2_DIR -> _BIT.b2

#define LCD_DATA_5 P2_OUT -> _BIT.b3

#define LCD_DATA_5_DIR P2_DIR -> _BIT.b3

#define LCD_DATA_6 P2_OUT -> _BIT.b4

#define LCD_DATA_6_DIR P2_DIR -> _BIT.b4

#define LCD_DATA_7 P2_OUT -> _BIT.b5

#define LCD_DATA_7_DIR P2_DIR-> _BIT.b5

//====================================================

/*or another PINS MAPPING TABLE:

#define LCD_RS P2_out -> _bit.b1

#define LCD_RS_DIR P2_dir -> _bit.b1

#define LCD_EN P2_out -> _bit.b2

#define LCD_EN_DIR P2_dir -> _bit.b2

#define LCD_DATA_4 P2_out -> _bit.b4

#define LCD_DATA_4_DIR P2_dir -> _bit.b4

#define LCD_DATA_5 P2_out -> _bit.b5

#define LCD_DATA_5_DIR P2_dir -> _bit.b5

#define LCD_DATA_6 P1_out -> _bit.b6

#define LCD_DATA_6_DIR P1_dir -> _bit.b6

#define LCD_DATA_7 P1_out -> _bit.b7

#define LCD_DATA_7_DIR P1_dir -> _bit.b7

*/

/******************************************************************

**********

* MODULE PRIVATE FUNCTIONS:

* void lcd_delay_us (unsigned long t);

* void lcd_delay_ms (unsigned long t);

* void lcd_put_byte(unsigned char rs, unsigned char data);

*

******************************************************************

************/

//

===========================================================

===================

//CHUONG TRINH DELAY:

void delay_ms(unsigned int ms){

while(ms ){

delay_cycles(1000);

}

Trang 8

unsigned int value;

//================================

void lcd_delay_us (unsigned long t)

{

int i;

for (i = 0; i<t; i++ )

delay_cycles(MCLK_F);

}

void lcd_delay_ms (unsigned long t)

{

int i;

for (i = 0; i<t; i++ )

delay_cycles(MCLK_F*1000);

}

//

===========================================================

===================

//THU VIEN LCD 1602:

//

******************************************************************

***********

// Send a byte of data (rs == 1) or command (rs == 0) to LCD

//

******************************************************************

***********

void lcd_put_byte(unsigned char rs, unsigned char data)

{

LCD_RS = 0;

if(rs) LCD_RS = 1;

lcd_delay_us(20);

LCD_EN = 0;

// send the high nibble

if (data&BIT4) LCD_DATA_4 = 1;

else LCD_DATA_4 = 0;

if (data&BIT5) LCD_DATA_5 = 1;

else LCD_DATA_5 = 0;

if (data&BIT6) LCD_DATA_6 = 1;

7

Trang 9

else LCD_DATA_6 = 0;

if (data&BIT7) LCD_DATA_7 = 1;

else LCD_DATA_7 = 0;

lcd_delay_us(20);

LCD_EN = 1;

lcd_delay_us(20);

LCD_EN = 0;

// send the low nibble

if (data&BIT0) LCD_DATA_4 = 1;

else LCD_DATA_4 = 0;

if (data&BIT1) LCD_DATA_5 = 1;

else LCD_DATA_5 = 0;

if (data&BIT2) LCD_DATA_6 = 1;

else LCD_DATA_6 = 0;

if (data&BIT3) LCD_DATA_7 = 1;

else LCD_DATA_7 = 0;

lcd_delay_us(20);

LCD_EN = 1;

lcd_delay_us(20);

LCD_EN = 0;

}

/******************************************************************

**********

* MODULE PUPLIC FUNCTIONS:

* void lcd_init(void)

* void lcd_clear(void)

* void lcd_gotoxy(unsigned char col, unsigned char row)

* void lcd_putc(char c)

* void lcd_puts(const char* s)

* void lcd_clr_puts (const char* s1 , const char* s2)

* void lcd_put_num (unsigned long val, char dec, unsigned char neg)

******************************************************************

************/

Trang 10

******************************************************************

***********

// Initialization for LCD module

//

******************************************************************

***********

void lcd_init(void)

{

// Set all signal pins as output

LCD_RS_DIR = 1;

LCD_EN_DIR = 1;

LCD_DATA_4_DIR = 1;

LCD_DATA_5_DIR = 1;

LCD_DATA_6_DIR = 1;

LCD_DATA_7_DIR = 1;

LCD_RS = 0;

LCD_EN = 0;

lcd_delay_ms(200); // delay for power on

// reset LCD

lcd_put_byte(0,0x30);

lcd_delay_ms(50);

lcd_put_byte(0,0x30);

lcd_delay_ms(50);

lcd_put_byte(0,0x32);

lcd_delay_ms(200); // delay for LCD reset

lcd_delay_ms(2); // wait for LCD

lcd_put_byte(0,FOUR_BIT & LINES_5X7); // Set LCD type

lcd_delay_ms(2); // wait for LCD

lcd_put_byte(0,DOFF&CURSOR_OFF&BLINK_OFF); // display off

lcd_delay_ms(2); // wait for LCD

lcd_put_byte(0,DON&CURSOR_OFF&BLINK_OFF); // display on

lcd_delay_ms(2); // wait for LCD

lcd_put_byte(0,0x01); // clear display and move cursor to home

lcd_delay_ms(2); // wait for LCD

9

Trang 11

lcd_put_byte(0,SHIFT_CUR_LEFT); // cursor shift mode

lcd_delay_ms(2); // wait for LCD

lcd_put_byte(0,0x01); // clear display and move cursor to home

lcd_delay_ms(2); // wait for LCD

}

//

******************************************************************

***********

// Clear the LCD

//

******************************************************************

***********

void lcd_clear(void)

{

lcd_put_byte(0,0x01); // display off

lcd_delay_ms(2); // wait for LCD

}

//

******************************************************************

***********

// Move the pointer of LCD to coordinate (column, row)

// Note that cursor is at (0,0) after reset of clear LCD

//

******************************************************************

***********

void lcd_gotoxy(unsigned char col, unsigned char row)

{

unsigned char address;

if(row!=0)

address=0x40;

else

address=0;

address += col;

lcd_put_byte(0,0x80|address);

lcd_delay_ms(2); // wait for LCD

}

Trang 12

******************************************************************

***********

// Put a writable character on LCD

// If the character is '\f', clear the LCD

// If the character is '\n', move cursor to the second line

//

******************************************************************

***********

void lcd_putc(char c)

{

switch(c){

case '\f':

lcd_put_byte(0, 0x01);

lcd_delay_ms(2); // wait for LCD

break;

case '\n':

lcd_gotoxy(0, 0x01);

break;

default:

lcd_put_byte(1, c);

lcd_delay_ms(2); // wait for LCD

break;

}

}

//

******************************************************************

***********

// Put a string s[] on LCD

// Please note that the string is ended with '/0' (or 0x00)

//

******************************************************************

***********

void lcd_puts(const char* s)

{

while(*s){

lcd_putc(*s++);

}

11

Trang 13

//

******************************************************************

***********

// Clear LCD Put string s1[] on line 1 and string s2[] on line 2

//

******************************************************************

***********

void lcd_clr_puts (const char* s1 , const char* s2)

{

lcd_clear ();

lcd_puts (s1);

lcd_gotoxy (0,1);

lcd_puts (s2);

}

//

******************************************************************

***********

// Put a constant or a number stored in 'val' on LCD

// The number must be multiplied and convert in type "unsigned long"

// or "unsigned int"

// dec: amount of digits after '.'

// neg: sign of the number, neg = 0 if the number is positive

//

// Example 1: lcd_put_num(val, 3, 0); // val = 12345

// will put "12.345" on the LCD

// Example 2: lcd_put_num(val, 6, 1); // val = 12345

// will put "-0.012345" on the LCD

//

// Note: This function may contain some bugs If you can detect and fix them

// , please contact me :d

//

******************************************************************

***********

void lcd_put_num (unsigned long val, char dec, unsigned char neg)

{

char i, j, digit,k;

long total;

Trang 14

long temp;

for (i = 0, total = val; total > 0;i++) // count number

total /= 10;

total = i;

if (neg !=0 )

lcd_putc ('-');

if ((total - dec) <=0) // if total < dec put 0.xxx

lcd_putc('0');

else

{

for (i=0; i< (total-dec); i++)

{

temp = 1;

for (j=1;j<(total-i);j++)

temp *=10;

digit = (val/temp)%10;

lcd_putc(digit + 0x30);

}

}

if (dec > 0)

{

lcd_putc('.');

if ( (dec - total)> 0) // ex: val = 55; dec = 3 put 0.055

{

for ( i = 0; i < (dec-total);i++)

lcd_putc('0');

k = 0;

}

else

k = total - dec;

for (i=k; i< total; i++)

{

temp = 1;

for (j=1;j<(total-i);j++)

temp *=10;

digit = (val/temp)%10;

lcd_putc(digit + 0x30);

13

Trang 15

}

}

}

void lcd_3n(unsigned long x)

{ lcd_putc((x/100)+48);

lcd_putc(((x/10)%10)+48);

lcd_putc((x%10)+48); }

void lcd_4n(unsigned long y)

{ lcd_putc((y/1000)+48);

lcd_putc(((y%1000)/100)+48);

lcd_putc(((y%100)/10)+48);

lcd_putc((y%10)+48); }

void canhbao()

{

P1OUT=BIT7;

delay_cycles(50000);

P1OUT&=~BIT7;

delay_cycles(50000);

}

unsigned long nhietdo;

int nhietdocaidat=30;

void main(void)

{

// Stop watchdog timer to prevent time out reset

WDTCTL = WDTPW + WDTHOLD;

BCSCTL1=CALBC1_1MHZ;

DCOCTL=CALDCO_1MHZ;

P1DIR=0x80;

P1DIR&=~0x01;

P1OUT = 0x00;

// -ngat

P1IE=(BIT4 + BIT5);

P1IES=(BIT4 + BIT5);

P1IFG&=~(BIT4 + BIT5);

Trang 16

UART_Init();

lcd_init();

lcd_clear();

ADC10CTL0=SREF_1+ADC10SHT_2+REFON+ADC10ON+ADC10IE;

ADC10CTL1=INCH_6;

ADC10AE0|=0x40;

CCTL0 = CCIE; // CCR0 interrupt enabled

CCR0 = 62500;

TACTL = TASSEL_2 + MC_1 + ID_3; // SMCLK,

_BIS_SR(GIE);

while(1)

{

nhietdo=(unsigned long)(ADC10MEM*1.5*100)/1023;

ADC10CTL0|=ENC+ADC10SC; //cho phep bien doi va bat dau bien doi ADC

lcd_gotoxy(0,0);

lcd_puts("nhiet do:");

lcd_gotoxy(10,0);

lcd_3n(nhietdo);

lcd_gotoxy(13,0);

lcd_putc(223);

lcd_gotoxy(14,0);

lcd_puts("C");

lcd_gotoxy(0,1);

lcd_puts("Khi gas:");

if(!(P1IN&0x01))

{

canhbao();

lcd_gotoxy(9,1);

lcd_puts("gas");

delay_cycles(100000);

UART_Write_String("HIEN THI GIA TRI LEN PC");

UART_Write_Char(10);

UART_Write_Char(10);

UART_Write_String("co GAS");

UART_Write_Char(10);

15

Trang 17

lcd_clear();

}

if(nhietdo>nhietdocaidat)

{

canhbao();

UART_Write_Char(10);

UART_Write_String("HIEN THI GIA TRI LEN PC");

UART_Write_Char(10);

UART_Write_Char(10);

UART_Write_String("nhiet do vuot nguong");

UART_Write_Char(10);

}

delay_cycles(10000);

}}

#pragma vector=ADC10_VECTOR

interrupt void ADC10_ISR(void)

{ bic_SR_register_on_exit(CPUOFF);}

#pragma vector=TIMER0_A0_VECTOR

interrupt void Timer_A (void)

{

UART_Write_Char(10);

UART_Write_Char(10);

UART_Write_String("HIEN THI GIA TRI LEN PC");

UART_Write_Char(10);

UART_Write_Char(10);

UART_Write_String(" Nhiet do la:");

UART_Write_Char(10);

UART_Write_Char(10);

UART_Write_Int(nhietdo);

UART_Write_Char(10);

UART_Write_Char(10);

UART_Write_Char(10);

}

#pragma vector=PORT1_VECTOR

interrupt void msp430(void)

{

Trang 18

if(P1IFG&BIT4)

{

nhietdocaidat++;

lcd_clear();

lcd_gotoxy(0,0);

lcd_puts("Nhiet do set:");

lcd_gotoxy(7,1);

lcd_3n(nhietdocaidat);

delay_cycles(500000);

lcd_clear();

P1IFG&=~BIT4;

}

if(P1IFG&BIT5)

{

nhietdocaidat ;

lcd_clear();

lcd_gotoxy(0,0);

lcd_puts("Nhiet do set:");

lcd_gotoxy(7,1);

lcd_3n(nhietdocaidat);

delay_cycles(500000);

lcd_clear();

P1IFG&=~BIT5;

}}

4 Đánh giá kết quả và hướng phát triển:

4.1 Kết quả:

- Mạch hoạt động tốt

4.2 Đánh giá:

- Mạch chưa đẹp

4.3 Hướng phát triển:

- Điều khiển đối tượng chữa cháy

Tài liệu tham khảo:

17

Ngày đăng: 05/12/2023, 05:35

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm

w