Mat linh kien

Một phần của tài liệu Bài giảng Xây dựng các hệ thống nhúng: Phần 2 (Trang 175 - 182)

C compiler header

A: mat linh kien

314

-Mụ tả nguyờn lớ làm việc

-Chương trỡnh điều khiển ghộp nối: /*

** 8255.c **

** Minh hoa PIO 8255 voi mode 0 (tat ca out_ports on 8255 Ports): ** A, B and C.

**

** 8255 is first setup with control word 0x80 ** Mode set flag active - bit 7 = 1

** Mode selection 0 - bits 6 5 = 0 0 ** Port A output - bit 4 = 0

** Port C (upper) output - bit 3 = 0 ** Mode selection 0 - bit 2 = 0 ** Port B output - bit 1 = 0

** Port C (lower) output - bit 0 = 0 **

** Dữ liệu ra sử dụng gọi hàm out_data (port, data) trong đú: ** Port A - 0 ** Port B - 1 ** Port C - 2 ** */ #include <stdio.h> #include <dos.h> /* Định nghĩa cỏc biến*/

#define DATA 0x0300 /* Cho ghộp nối lập biến DATA=base addr*/ #define STATUS DATA+1

#define CONTROL DATA+3 /*CONTROL=DATA+3*/ void reset(void);

void write_clock(int a1a0); void set_control_word(void); void out_data(int port, int data);

void main(void) {

315

int port; int data;

/*bat dau chuong trinh*/ reset();

set_control_word();

/* Bay gio da co the cho 8255 chay */

/* Thu dua ra cac so Hex tren 3 cong A,B,C */

printf("An <ENTER> DE KIEM TRA CAC GIA TRI TU a den f \n"); /* for(port=0;port<3;port++)*/

/*{*/ getchar();

port=0; /*Tam thoi voi port A*/ printf("Dua ra aa\n"); out_data(port, 0xaa); getchar(); printf("Dua ra bb\n"); out_data(port, 0xbb); getchar(); printf("Dua ra cc\n"); out_data(port, 0xcc); getchar(); printf("Dua ra dd\n"); out_data(port, 0xdd); getchar(); printf("Dua ra ee\n"); out_data(port, 0xee); getchar(); printf("Dua ra ff\n"); out_data(port, 0xff); /* }*/

/*Nhan bat ki so nao tu 00-99*/

printf("\n Go vao bat ki so nao tu 00 den 99 va ENTER \n"); while(1)

{

scanf("%x",&data); /*nhan luon so kieu hexa de dua ra cong*/ for (port=0;port<3 ;port++ )

{

316

} }/*while*/ }

/*Cac ham ho tro*/

void set_control_word(void) {

/*int a1a0 = 0x03;*/

outportb(CONTROL, 0x80); /* out control word = 0x80 */ /* bring a1 a0 to 1 1, WR to 1 */

/*outportb(CONTROL, */

/* ( ((0x00) | (a1a0 << 1) | 0x01) ^ 0x0b) & 0x0f); */ /* now wink WR low and high */

/*write_clock(a1a0); */ }

void out_data(int port, int data) {

/*int a1a0 = port;*/

outportb(DATA, data); /* put data on data leads */ /* set a1 and a0 to 0 0, 0 1 or 1 0, WR to 1 */

/*outportb(CONTROL,( ((0x00) | (a1a0 << 1) | 0x01) ^ 0x0b) & 0x0f);*/ /* now wink WR low and high */

/* write_clock(a1a0); */ }

void write_clock(int a1a0) {

/* bring WR low */ outportb(CONTROL,

(((0x00) | (a1a0<<1) & (~0x01) ) ^ 0x0b) & 0x0f); /* bring WR back high */

outportb(CONTROL,

317

}

void reset(void) {

/* bring reset high */

outportb(CONTROL, 0x08^0x0b); }

;

Ghộp ADC 0809/DAC 0832

Phõn bố địa chỉ:

200 ~ 207 Eight Channel Analog to Digital Converter 208 ~ 20F Digital to Analog Converter 1

210 ~ 217 Digital to Analog Converter 2

218 ~ 21F Analog to Digital Converter Ready Line And 3 Digital Inputs 220 ~ 227 Programmable Peripheral Interface

228 ~ 22F Spare Select Line 230 ~ 237 Spare Select Line 238 ~ 23F Spare Select Line

240 ~ 247 Eight Channel Analog to Digital Converter 248 ~ 24F Digital to Analog Converter 1

250 ~ 257 Digital to Analog Converter 2 (optional)

258 ~ 25F Analog to Digital Converter Ready Line And 3 Digital Inputs 260 ~ 267 Programmable Peripheral Interface

268 ~ 26F Spare Select Line 270 ~ 277 Spare Select Line 278 ~ 27F Spare Select Line

280 ~ 287 Eight Channel Analog to Digital Converter 288 ~ 28F Digital to Analog Converter 1

290 ~ 297 Digital to Analog Converter 2 (optional)

298 ~ 29F Analog to Digital Converter Ready Line And 3 Digital Inputs 2A0 ~ 2A7 Programmable Peripheral Interface

2A8 ~ 2AF Spare Select Line 2B0 ~ 2B7 Spare Select Line 2B8 ~ 2BF Spare Select Line

318

2C0 ~ 2C7 Eight Channel Analog to Digital Converter 2C8 ~ 2CF Digital to Analog Converter 1

2D0 ~ 2D7 Digital to Analog Converter 2 (optional)

2D8 ~ 2DF Analog to Digital Converter Ready Line And 3 Digital Inputs 2E0 ~ 2E7 Programmable Peripheral Interface

2E8 ~ 2EF Spare Select Line 2F0 ~ 2F7 Spare Select Line 2F8 ~ 2FF Spare Select Line

300 ~ 307 Eight Channel Analog to Digital Converter 308 ~ 30F Digital to Analog Converter 1

310 ~ 317 Digital to Analog Converter 2 (optional)

318 ~ 31F Analog to Digital Converter Ready Line And 3 Digital Inputs 320 ~ 327 Programmable Peripheral Interface

328 ~ 32F Spare Select Line 330 ~ 337 Spare Select Line 338 ~ 33F Spare Select Line

340 ~ 347 Eight Channel Analog to Digital Converter 348 ~ 34F Digital to Analog Converter 1

350 ~ 357 Digital to Analog Converter 2 (optional)

358 ~ 35F Analog to Digital Converter Ready Line And 3 Digital Inputs 360 ~ 367 Programmable Peripheral Interface

368 ~ 36F Spare Select Line 370 ~ 377 Spare Select Line 378 ~ 37F Spare Select Line

380 ~ 387 Eight Channel Analog to Digital Converter 388 ~ 38F Digital to Analog Converter 1

390 ~ 397 Digital to Analog Converter 2 (optional)

398 ~ 39F Analog to Digital Converter Ready Line And 3 Digital Inputs 3A0 ~ 3A7 Programmable Peripheral Interface

3A8 ~ 3AF Spare Select Line 3B0 ~ 3B7 Spare Select Line 3B8 ~ 3BF Spare Select Line

3C0 ~ 3C7 Eight Channel Analog to Digital Converter 3C8 ~ 3CF Digital to Analog Converter 1

3D0 ~ 3D7 Digital to Analog Converter 2 (optional)

3D8 ~ 3DF Analog to Digital Converter Ready Line And 3 Digital Inputs 3E0 ~ 3E7 Programmable Peripheral Interface

319

3E8 ~ 3EF Spare Select Line 3F0 ~ 3F7 Spare Select Line 3F8 ~ 3FF Spare Select Line

320

Ghộp nối với PIC 12F675

Making an LM35 temperature recorder with PIC 12F675.

http://www.best-microcontroller-projects.com/12F675-tutorial-mikroc-1-7-source.html

This page shows you how you can make an LM35 an temperature recorder by using the 12F675 PIC microcontroller as the controller and data store.

It generates serial output so that you can view the results on a PC and it also calculates the temperature reading in Fahrenheit sending both to the serial port at half second intervals.

The project uses the code from the previous tutorials to report the temperature to the PC using the serial port so the serial RS232 data format is generated in software.

Jump to circuit.

Jump to Solderless breadboard.

Jump to Circuit Diagram.

Jump to Software.

LM35DZ

The LM35 is a precision temperature sensor. It is guaranteed accurate to ±ẳ°C at 25°C (At different temperatures it is less accurate! but it is never more than 2°C inaccurate and it probably is not this inaccurate anyway it's just the manufacturers maximum limits that may apply).

Typically is stays accurate to within ±ắ°C over its temperature range so this is a good general purpose sensor and it's easy to use.

It generates a linear output voltage using a centigrade scale - generating 10mV of output voltage for every degree centigrade change and there are several versions for operation over different temperature ranges:

LM35 -55°C to 150°C

LM35C -40°C to 110°C

LM35D 0°C to 100°C

Note: The project code calculates the temperature in Fahrenheit and generates both Centigrade and Fahrenheit outputs to the serial port.

Một phần của tài liệu Bài giảng Xây dựng các hệ thống nhúng: Phần 2 (Trang 175 - 182)

Tải bản đầy đủ (PDF)

(196 trang)