PIC PIC Harvard Architecture Reduce Instruction Set Computing

  • Slides: 61
Download presentation

สถาปตยกรรมและการออกแบบ PIC • PIC ถกออกแบบใหมคณสมบตดงตอไปน – Harvard Architecture – Reduce Instruction Set Computing (RISC)

สถาปตยกรรมและการออกแบบ PIC • PIC ถกออกแบบใหมคณสมบตดงตอไปน – Harvard Architecture – Reduce Instruction Set Computing (RISC) – Single Word Instruction – Pipeline

Program Memory Mode

Program Memory Mode

PICDEM™ PIC 18 EXPLORER PICkit™ DEMONSTRATION BOARD Starter Kit ใส PIC 18 F 8722

PICDEM™ PIC 18 EXPLORER PICkit™ DEMONSTRATION BOARD Starter Kit ใส PIC 18 F 8722 )ไฟ 5 V) Plug-In Module ��� PIC 18 F 87 J 11 )�� 3. 3 V)

PICDEM™ PIC 18 EXPLORER DEMONSTRATION BOARD PIC 18 F 8722 Connector ������ Plug In

PICDEM™ PIC 18 EXPLORER DEMONSTRATION BOARD PIC 18 F 8722 Connector ������ Plug In Module PIC 18 F 87 J 11 In Circuit Debugger PICkit Connector

PICDEM™ PIC 18 EXPLORER DEMONSTRATION������ BOARDs 4 PIC 18 F 8722 PIC 18 F

PICDEM™ PIC 18 EXPLORER DEMONSTRATION������ BOARDs 4 PIC 18 F 8722 PIC 18 F 87 J 11 ����� PIC ���� (PIC 18 F 8722) ����� PIM (PIC 18 F 87 J 11) LED �������� JP 1 ������ LED 8 ดวง

PICDEM™ PIC 18 EXPLORER ����� DEMONSTRATION 32. 768 BOARD k. Hz ������ Timer 1

PICDEM™ PIC 18 EXPLORER ����� DEMONSTRATION 32. 768 BOARD k. Hz ������ Timer 1 ���������� ��� MPC 9701 A 25 LC 256 SPI EEPROM JP 2 Enable/Disable EEPROM

การพฒนาโปรแกรมโดยใช Demo PIC 5. Step three : Create New Project File กด Browse เลอก

การพฒนาโปรแกรมโดยใช Demo PIC 5. Step three : Create New Project File กด Browse เลอก Folder และชอ Project File ทตองการ

ตวอยางโปรแกรมไฟวง Demo 1. c ADCON 0 bits. ADON = 1; while(1) { ADCON 0

ตวอยางโปรแกรมไฟวง Demo 1. c 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; #include <p 18 f 8722. h> #include <adc. h> #include <delays. h> #include <timers. h> #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(result); } }

Library ของ MPLab C 18 • ฟงกชนทมากบ Library ของ MPLab. C 18 มทงหมด 4

Library ของ MPLab C 18 • ฟงกชนทมากบ Library ของ MPLab. C 18 มทงหมด 4 กลมคอ 1. Hardware Peripheral Function • • A/D Converter Input Capture I 2 C I/O Port Microwire Pulse-Width Modulation SPI Timer

Library ของ MPLab C 18 2. Software Peripheral Function • • • External LCD

Library ของ MPLab C 18 2. Software Peripheral Function • • • External LCD Function External CAN 2510 Function Software I 2 C Function Software SPI Function Software UART Function

Library ของ MPLab C 18 3. General Software Library • • • Character Classification

Library ของ MPLab C 18 3. General Software Library • • • Character Classification Functions Data Conversion Functions Memory and String Manipulation Functions Delay Functions Reset Functions Character Output Functions 4. Math Libraries • 32 -Bit Floating Point Library • The C Standard Library Math Functions

โครงสรางการเขยนโปรแกรมภาษา /* Include Files */ #include <p 18 xxxxx. h> #include … …. .

โครงสรางการเขยนโปรแกรมภาษา /* Include Files */ #include <p 18 xxxxx. h> #include … …. . /* Symbol Definitions */ #define MAX 100 #define … …. #pragma config WDTEN = OFF /* Global Variables */ int x, y, z, …. . char a, b, c, …… …. . /* Function Declarations */ int Func(char r) { int x, y; …………. return … } …. …. /* Start of MAIN Program */ void main(void) { …………. . } C

 • ตองประกาศฟงกชนกอนทกคร งทจะถกเรยกใช float Sin. Wave(float x); Void Send. Wave(char x); void main(void)

• ตองประกาศฟงกชนกอนทกคร งทจะถกเรยกใช float Sin. Wave(float x); Void Send. Wave(char x); void main(void) { float t, Output; for(t=0; t<1. 0; t+=0. 1) { Output = Sin. Wave(255. 0, t); Send. Wave(Output); } }

Local & Global Variable • Local Variable คอตวแปรทสามารถใชไดในฟงกชนทมการประก าศไวเทานน • float. Global Variable Sin.

Local & Global Variable • Local Variable คอตวแปรทสามารถใชไดในฟงกชนทมการประก าศไวเทานน • float. Global Variable Sin. Wave(float x); void Sin. Wave(float A, float t) Void Send. Wave(void); { คอตวแปรทสามารถเรยกใชในฟงกชนใดๆกได float x; // x is global variable x = A*sin(2. 0*3. 14*t); // x is global variable void main(void) { float x; // x is local variable for(x=0; x<1. 0; x+=0. 1) { Output = Sin. Wave(255. 0, x); Send. Wave(); } } } void Send. Wave(void) { PORTA = (char) x; // x is global variable }

ตวแปร Array void main(void) { int LED[] ={ 0 b 00000001, 0 b 00000010,

ตวแปร Array void main(void) { int LED[] ={ 0 b 00000001, 0 b 00000010, 0 b 00000100, 0 b 00001000, 0 b 00010000, 0 b 00100000, 0 b 01000000, 0 b 10000000}; TRISAbits. TRISA 0=1; TRISD = 0; PORTD = 0; ADCON 1 = 0 b 00001110; ADCON 2 = 0 b 10001010; 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; PORTD=LED[shift]; shift++; shift %=8; } } Delay 10 KTCYx(result);