Microprocessors and Applications ADC UART Microprocessors and Applications
- Slides: 38
Microprocessors and Applications ADC & UART
Microprocessors and Applications Analog & Digital Signal Analog Signal Digital Signal
Analog to Digital Converter Sampling and Hold Microprocessors and Applications Quantize
Sampling Rate Selection Sampling Rate Microprocessors and Applications
Sampling Rate Selection Microprocessors and Applications Resolution LSB = (Vref+Vref-)/2 k
ADC ชนด Successive Approximation Microprocessors and Applications
ADC ของ PIC 18 F 8722 Microprocessors and Applications • PIC 18 F 8722 มวงจร Analog to Digital Converter ขนาด 10 bit ทงหมด 16 วงจร (AN 0 -AN 15)
ADC ของ PIC 18 F 8722 Microprocessors and Applications
ADC ของ PIC 18 F 8722 Microprocessors and Applications
ADC ของ PIC 18 F 8722 Microprocessors and Applications
Microprocessors and Applications Register ของ ADC • PIC ม Register ทเกยวกบ ตวคอ 1. 2. 3. 4. 5. ADC ทงหมด A/D Result High Register (ADRESH) A/D Result Low Register (ADRESL) A/D Control Register 0 (ADCON 0) A/D Control Register 1 (ADCON 1) A/D Control Register 2 (ADCON 2) 5
ADRESH และ ADRESL • ADRESH และ ADRESL เปน Register ทใชเกบผลลพธของการแปลง ADC Microprocessors and Applications
ADCON 0 Microprocessors and Applications
ADCON 1 Microprocessors and Applications • ADCON 1 เปน Register ทใชกำหนดให AN ตวใดทำงานเปน Analog Input Port หรอทำงานเปน Digital I/O Port (PCFG 3: 0) • และกำหนดให RA 3/AN 3 เปน VRef+ และ RA 2/AN 2 เปน VRef- (VCFG 1: 0)
ADCON 1 Microprocessors and Applications
ADCON 2 • ADCON 2 เปน Register ทใชกำ หนด Acquisitio n Time ของวงจร ADC Microprocessors and Applications
Acquisition Time Microprocessors and Applications
ขนตอนการแปลง ADC Microprocessors and Applications
Microprocessors and Applications #include <p 18 f 8722. h> #include <adc. h> #include <delays. h> #include <timers. h> ADCON 0 bits. ADON = 1; while(1) { ADCON 0 bits. GO=1; while(ADCON 0 bits. GO); result = ADRES; result >>=2; if(result==0) result = 1; #define NUMBER_OF_LEDS 8 #pragma code int result; int shift; void main(void) { TRISAbits. TRISA 0=1; TRISD = 0; PORTD = 0; ADCON 1 = 0 b 00001110; ADCON 2 = 0 b 10001010; // } PORTD = result; PORTD=1<<shift; shift++; shift %=8; } Delay 10 KTCYx(20);
Microprocessors and Applications การสอสารแบบดจตอล • การสอสารแบบดจตอลสามารถแบงออกเปน 1. การสอสารแบบขนาน 2 กลมคอ (Parallel Communication) § IEEE 488 หรอ General Purpose Interface Bus (GPIB) § IEEE 1248 หรอ Centronics Parallel Protocol § SCSI (Small Computer System Interface) § IDE (Integrated Drive Electronics) § ISA (Industrial Standard Architecture) § PCI (Peripheral Component Interconnect) § AGP (Accelerated Graphics Port)
Microprocessors and Applications การสอสารแบบดจตอล 2. § § § § การสอสารแบบอนกรม (Serial Communication) RS 232 RS 422 RS 485 UART (Universal Asynchronous receiver-transmitter) USART (Universal Synchronous- Asynchronous receiver-transmitter) MIDI IEEE 1394 หรอ Fire. Wire CAN (Controller Area Network) USB (Universal Serial Bus) I 2 C (Inter Integrated Circuit) SPI (Serial Peripheral Interface bus) Micro-wire Ethernet Fiber optics Bluetooth Wi. Fi
Universal Asynchronous Receiver and Transmitter (UART) § 9 bit-Transmission ประกอบดวย 1 start, 9 -bit Data (บทท 8 มกใชเปน parity bit), 1 stop Bit § parity Bit ใชในการตรวจสอบความถกตองของ ขอมล มอย 2 แบบคอ qeven parity, parity bit = 1 ถาจำนวนบทขอมลทเปน 1 เปนเลขค qodd parity, parity bit = 1 Microprocessors and Applications
Microprocessors Universal Asynchronous and Applications Receiver and Transmitter (UART) • BAUD Rate หมายถงจำนวนบททงหมด (start + stop + data + parity) ทสามารถรบสงไดใน 1 วนาท • BAUD Rate มาตรฐานมดงน 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200, 128000 และ 256000
Register ทเกยวของ Microprocessors and Applications
Register ทเกยวของ Microprocessors and Applications
Register ทเกยวของ Microprocessors and Applications
ตารางการเซท Configuration Bit สำหรบ คำนวณ BAUD Rate Configuration Bits SYNC BRG 16 BRGH 0 0 0 1 1 1 0 x 1 1 x Microprocessors and Applications BRG/EUSART Mode BAUD Rate Formula 8 -bit/Asynchronous 16 -bit/Asynchronous 8 -bit/Synchronous 16 -bit/Synchronous Fosc/[64(n+1)] Fosc/[16(n+1)] Fosc/[4(n+1)] n = SPBRGx (8 -bit Asynchronous) หรอ n = SPBRGHx: SPBRGx (16 -bit Asynchronous
วธการคำนวณ BAUD Rate Microprocessors and Applications
ตวอยางการคำนวณ BAUD Rate Microprocessors and Applications
Microprocessors and Applications void UART_Write(char data) void UART_Init(void) { { while(!TRMT); BRGH = 1; TXREG = data; } BRG 16 = 0; SPBRG = 25; char UART_TX_Empty() SYNC = 0; //Setting Asynchronous Mode, ie UART SPEN = 1; //Enables Serial Port TRISC 7 = 1; //As Prescribed in Datasheet TRISC 6 = 0; //As Prescribed in Datasheet void UART_Write_Text(char *text) CREN = 1; //Enables Continuous Reception { TXEN = 1; //Enables Transmission { return TRMT; } int i; for(i=0; text[i]!='