General Purpose Input/Output

Slides:



Advertisements
Similar presentations
Autumn 2012C.-S. Shieh, EC, KUAS, Taiwan1 The 8051 Family Microcontroller Chin-Shiuh Shieh Department of Electronic Engineering.
Advertisements

Lab7: Introduction to Arduino
Programmable Interval Timer
Input/Output Ports and Interfacing ELEC 330 Digital Systems Engineering Dr. Ron Hayne Images Courtesy of Ramesh Gaonkar and Delmar Learning.
Embedded Systems 7763B Mt Druitt College of TAFE Electrical Engineering Lesson 2 LCD Display Interfacing.
Embedded Programming and Robotics Lesson 9 Keypad and LCD Display 1.
1-1 SYS Module System Clocks FXTAL BCLK Reset Circuit Reset Conditions Bootstrap Initialization.
16x2 LCD Module on DE2-115 數位電路實驗 TA: 吳柏辰 Author: Trumen.
Part 1 Using the ARM board And start working with C Tutorial 5 and 6
Digital Outputs LCD Display
Department of Electrical Engineering, National Taiwan Ocean University NuMicro Learning Board Introduction 1/29/2015 Richard Kuo Assistant.
2/26/2015 Richard Kuo Assistant Professor
1 Chapter 1: Parallax Serial LCD Display Smart Sensors and Applications Chapter 1: Parallax Serial LCD Display Presented by: Andy Lindsay Parallax, Inc.
Universal Asynchronous RX/TX
Department of Electrical Engineering, National Taiwan Ocean University NuMicro MCU Learning Board SDK Installation 3/7/2013 Richard.
MOBILE OPERATING ROBOT ON EMBEDDED SYSTEM
Department of Electrical Engineering, National Taiwan Ocean University Pulse Width Modulation 4/25/2013 Richard Kuo Assistant Professor.
Department of Electrical Engineering, National Taiwan Ocean University Motor Control 5/2/2013 Richard Kuo Assistant Professor.
Department of Electrical Engineering, National Taiwan Ocean University C Programming 3/14/2013 Richard Kuo Assistant Professor.
NuMicro MCU Learning Board Introduction
Department of Electrical Engineering, National Taiwan Ocean University Analog-to-Digital Converter (ADC) 4/18/2013 Richard Kuo Assistant.
Department of Electrical Engineering, National Taiwan Ocean University LCD Display 3/28/2013 Richard Kuo Assistant Professor.
UART: Universal Asynchronous RX/TX
Department of Electrical Engineering, National Taiwan Ocean University Appendix – NUC140 pin assignment 9/29/2012 Richard Kuo Assistant.
Cortex-M0 MCU Interface and Driver Design - Course Overview
Department of Electrical Engineering, National Taiwan Ocean University Basic Electronics 3/7/2013 Richard Kuo Assistant Professor.
Instrumentation & Control Engg. Section Electrical Engineering Department Ahmedabad , Gujarat.
Department of Electrical Engineering, National Taiwan Ocean University ARM Cortex-M0 Introduction 3/1/2012 Richard Kuo Assistant Professor.
Department of Electrical Engineering, National Taiwan Ocean University Universal Serial Bus & SD card 5/30/2013 Richard Kuo Assistant.
UniMAP 1 Interfacing Peripherals. UniMAP 2 Interfacing devices on Embedded Linux In general, to interface to a device connected to an embedded Linux platform.
8279 KEYBOARD AND DISPLAY INTERFACING
Department of Electrical Engineering, National Taiwan Ocean University Timer/WatchDog /RTC 4/11/2013 Richard Kuo Assistant Professor.
3/23/2015 Richard Kuo Assistant Professor
Serial Peripheral Interface
Chapter 10 Glass Bliss Using the Parallel Master Port to communicate with Alphanumeric LCD displays.
Oracle Fusion Applications 11gR1 ( ) Functional Overview (L2) Manage Inbound Logistics (L3) Manage Receipts.
Oracle Fusion Applications 11gR1 ( ) Functional Overview (L2) Manage Outbound Logistics (L3) Pick Loads.
Oracle Fusion Applications 11gR1 ( ) Functional Overview (L2) Manage Inbound Logistics (L3) Manage Supplier Returns.
8279 KEYBOARD AND DISPLAY INTERFACING
EE 316 Computer Engineering Junior Lab Project 2 Digital Yahtzee.
Oracle Fusion Applications 11gR1 ( ) Functional Overview (L2) Manage Inbound Logistics (L3) Manage and Disposition Inventory Returns.
Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC.
INTEL CONFIDENTIAL Intel® Smart Connect Technology Remote Wake with WakeMyPC November 2013 – Revision 1.2 CDI/IBP #:
Department of Electrical Engineering, National Taiwan Ocean University I2C Bus 5/16/2013 Richard Kuo Assistant Professor.
Department of Electrical Engineering, National Taiwan Ocean University Controller Area Network bus 5/30/2013 Richard Kuo Assistant Professor.
KEYBOARD/DISPLAY CONTROLLER - INTEL Features of 8279 The important features of 8279 are, Simultaneous keyboard and display operations. Scanned keyboard.
LED AND KEYBOARD INTERFACING PREPARED BY :- PREPARED BY :- RAVAL AKASH ( ) RAVAL AKASH ( ) PATEL HARDIK ( ) PATEL HARDIK.
A.D.Patel institute of technology Sub : LCD and Keyboard interfacing with AVR. prepared by, chokshi abhi p ( ) Guided by, Prof. Asif Thakor.
WATER LEVEL INDICATOR AND AUTOMATIC MOTOR SWITCHING SYSTEM
Sitarambhai Naranjibhai Patel Institute of Technology and Research Centre, Umrakh, Bardoli. A Presentation On “ 16x2 LCD Interfacing with AVR atmega32.
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Oracle Proprietary and Confidential. 1.
CEng3361 CENG 336 INT. TO EMBEDDED SYSTEMS DEVELOPMENT Spring 2011 Recitation 06.
Connectivity to bank and sample account structure
Serial Peripheral Interface
Peripherals – Keypad The Keypad provides a simple means of numerical data or control input. The keys can be attributed whatever data or control values.
LCD Interfacing using Atmega 32
CS4101 Introduction to Embedded Systems Lab 10: Tasks and Scheduling
Cortex-M0 MCU Clocks & Pins
LCD and Keyboard Interfacing
UNIVERSAL COLLEGE OF ENGINEERING & TECHNOLOGY
GANDHINAGAR INSTITUTE OF TECHNOLOGY
NuMicro MCU New Project Express Creation
EET 2261 Unit 11 Controlling LCD and Keypad
LCD and Keyboard Interfacing
EET 2261 Unit 11 Controlling LCD and Keypad
LCD and Keyboard Interfacing
LCD and Keyboard Interfacing
LCD and Keyboard Sepehr Naimi
8051 Micro Controller.
LCD and Keyboard Interfacing
Presentation transcript:

General Purpose Input/Output 3/21/2013 Richard Kuo Assistant Professor

Outline Cortex-M0 MCU General Purpose Input/Output 4.NuMicro_GPIO.PPT Exercise : GPIO to scan 3x3 keypad (Smpl_7seg_Keypad) Exercise : GPIO controlled by 3x3 keypad (Smple_GPIO_Keypad) Exercise : GPIO to read Body Infrared Sensor (Smpl_GPIO_BodyInfrared) Exercise : GPIO connecting to LCM16x2 (Smpl_GPIO_LCM16x2) Exercise : GPIO interface to 16x16 LED Matrix (Smpl_GPIO_LED16x16)

Nu-LB-NUC140 Learning Board 7 segment LEDs RGB LED GPA12,13,14 LEDs GPC12,13,14,15 3x3Keypad Buzzer GPB11

3x3 Keypad schematic

Control Pins used for 3x3 Keypad Column control : GPA2, 1, 0 Raw control : GPA 3, 4, 5 Key1 = GPA3 & GPA2 Key2 = GPA3 & GPA1 Key3 = GPA3 & GPA0 Key4 = GPA4 & GPA2 Key5 = GPA4 & GPA1 Key6 = GPA4 & GPA0 Key7 = GPA5 & GPA2 Key8 = GPA5 & GPA1 Key9 = GPA5 & GPA0

Smpl_7seg_Keypad Display Number = 5 Press middle key

Keypad Driver – Scankey.c #include <stdio.h> #include "Driver\DrvGPIO.h" #include "ScanKey.h" void delay(void) { int j; for(j=0;j<1000;j++); } void OpenKeyPad(void) uint8_t i; /* Initial key pad */ for(i=0;i<6;i++) DrvGPIO_Open(E_GPA, i, E_IO_QUASI); void CloseKeyPad(void) DrvGPIO_Close(E_GPA, i);

Keypad Driver – Scankey.c uint8_t Scankey(void) { uint8_t act[4]={0x3b, 0x3d, 0x3e}; uint8_t i,temp,pin; for(i=0;i<3;i++) temp=act[i]; for(pin=0;pin<6;pin++) if((temp&0x01)==0x01) DrvGPIO_SetBit(E_GPA,pin); else DrvGPIO_ClrBit(E_GPA,pin); temp>>=1; } delay(); if(DrvGPIO_GetBit(E_GPA,3)==0) return(i+1); if(DrvGPIO_GetBit(E_GPA,4)==0) return(i+4); if(DrvGPIO_GetBit(E_GPA,5)==0) return(i+7); return 0;

Smpl_7seg_Keypad int32_t main (void) { int8_t number; UNLOCKREG(); DrvSYS_Open(48000000); LOCKREG(); OpenKeyPad(); while(1) number = Scankey(); // scan keypad to get a number (1~9) show_seven_segment(0,number); // display number on 7-segment LEDs DrvSYS_Delay(5000); // delay time for keeping 7-segment display close_seven_segment(); // turn off 7-segment LEDs }

Smpl_GPIO_Keypad Press key Control GPIO outputs GPIOs control 4-port Relay

Smpl_GPIO_Keypad Press key1 Press key2 Press key3 Press key4 Relay #1 off Relay #2 off Relay #3 off Relay #4 off Vcc = 3.3V, GPIO output hi (base)  Relay Control pin = low (collector)

Smpl_GPIO_Keypad int32_t main (void) { char TEXT1[16] = "number: "; int8_t i, number; UNLOCKREG(); SYSCLK->PWRCON.XTL12M_EN = 1; SYSCLK->CLKSEL0.HCLK_S = 0; LOCKREG(); Initial_panel(); clr_all_panel(); for (i=0; i<9; i++) { DrvGPIO_Open(E_GPB, i, E_IO_OUTPUT); DrvGPIO_ClrBit(E_GPB, i); } OpenKeyPad(); print_lcd(0,"Smpl_GPIO_Keypad"); while(1) { number = Scankey(); sprintf(TEXT1+8,"%d", number); print_lcd(1,TEXT1); if (number!=0) DrvGPIO_SetBit(E_GPB, number-1); else for (i=0; i<9; i++) DrvGPIO_ClrBit(E_GPB, i); }

Smpl_GPIO_BodyInfrared Display Detected ! Human Body Infrared Detector

Smpl_GPIO_BodyInfrared int main(void) { UNLOCKREG(); SYSCLK->PWRCON.XTL12M_EN = 1; //Enable 12Mhz crystal and set HCLK=12Mhz SYSCLK->CLKSEL0.HCLK_S = 0; LOCKREG(); DrvGPIO_Open(E_GPA, 0, E_IO_INPUT); // set GPA0 to input mode Initial_panel(); clr_all_panel(); print_lcd(0, "Body Infrared "); print_lcd(1, "GPA0 input......"); while(1) { if (DrvGPIO_GetBit(E_GPA,0)==0) print_lcd(2, "Object Detected!"); else print_lcd(2, "No Detection! "); }

LCD MODULE - PC1602 Operating at 5V

LCM16x2 Pin Description // LCD 16x2 Module // pin1 Gnd (to Gnd) // pin2 Vcc: (to +5V) // pin3 Vo : brightness control (to Gnd) // pin4 RS : 1=Data, 0=Instruction (to GPA0) // pin5 RW : 1=Read, 0=Write (to GPA1) // pin6 E : Chip Enable (to GPA2) // pin7~14 : D0~D7 (to GPE0~7) // pin15 A : backlight+ (to Vcc) no backlight, no coonection // pin16 K : backlight- (to Gnd) no backlight, no connection // DB[7:0] : Description // 0000_0001: Clear Display // 0000_001x: Return to Home (Display RAM address=0) // 0000_01DS: Cursor move direction, Display Shift // 0000_1DCB: Display/Cursor/Blinking on/off // 0001_SRxx: Curosor move, shift R/L // 01xx_xxxx: set CGRAM // 1xxx_xxxx: set DDRAM

Smpl_GPIO_LCM16x2 void LCD_data(unsigned char wdata) { LCD_DATA=wdata; LCD_RS_SET; LCD_RW_CLR; LCD_E_CLR; DrvSYS_Delay(100); LCD_E_SET; } void LCD_cmd(unsigned char wdata) LCD_RS_CLR;

Smpl_GPIO_LCM16x2 void Init_LCM16x2(void) { LCD_DATA=0; DrvSYS_Delay(40000); // wait time >40ms after Vcc>4.5V LCD_cmd(0x38); // 8-bit Interface DrvSYS_Delay(1000); LCD_cmd(0x38); DrvSYS_Delay(37); LCD_cmd(0x06); // Cursor Move to right, no shift LCD_cmd(0x0C); // Display ON, Cursor Off, Blinking off LCD_cmd(0x01); // Display Clear DrvSYS_Delay(1520); }

Smpl_GPIO_LCM16x2 void display_xy(uint8_t x,uint8_t y) { if(y==1) x+=0x40; x+=0x80; LCD_cmd(x); } void display_char(uint8_t x, uint8_t y, unsigned char dat) display_xy(x,y); LCD_data(dat); void display_string(uint8_t x,uint8_t y,unsigned char *s) { uint8_t i; display_xy(x,y); i=0; while((x+i)<16) LCD_data(*s); s++; i++; }

Smpl_GPIO_LCM16x2 main() { unsigned char LcdBuf1[16]= "Welcome to NTOU "; unsigned char LcdBuf2[16]= "Cortex-M0 MCU !!"; Init_LCM16x2(); display_string(0,0,LcdBuf1); // display line 1 display_string(0,1,LcdBuf2); // display line 2 }

Smpl_GPIO_LCM8x2

Smpl_GPIO_LCM8x2 // // NuMicro Nu-LB-NUC140 // Sample Code : Smpl_GPIO_LCM8x2 // LCD 8x2 Module // pin1 Vss: (to Gnd) // pin2 Vcc: to +5V (to +5V) // pin3 Vee : brightness control (to Gnd) // pin4 RS : 1=Data, 0=Instruction (to GPA0) // pin5 RW : 1=Read, 0=Write (to GPA1) // pin6 E : Chip Enable (to GPA2) // pin7~14 : D0~D7 (to GPB0~7)

Smpl_GPIO_LCM8x2 #include <stdio.h> #include "NUC1xx.h" #include "Driver\DrvGPIO.h" #include "Driver\DrvUART.h" #include "Driver\DrvSYS.h" #define LCD_DATA GPIOB->DOUT // D0~7 pin = GPB0~7 #define LCD_RS_HI DrvGPIO_SetBit(E_GPA,0) // RS pin = GPA0 #define LCD_RS_LO DrvGPIO_ClrBit(E_GPA,0) #define LCD_RW_HI DrvGPIO_SetBit(E_GPA,1) // RW pin = GPA1 #define LCD_RW_LO DrvGPIO_ClrBit(E_GPA,1) #define LCD_E_HI DrvGPIO_SetBit(E_GPA,2) // E pin = GPA2 #define LCD_E_LO DrvGPIO_ClrBit(E_GPA,2)

Smpl_GPIO_LCM8x2 void Init_GPIO(void) { DrvGPIO_Open(E_GPA, 0, E_IO_OUTPUT); DrvGPIO_Open(E_GPA, 1, E_IO_OUTPUT); DrvGPIO_Open(E_GPA, 2, E_IO_OUTPUT); DrvGPIO_ClrBit(E_GPA, 0); DrvGPIO_ClrBit(E_GPA, 1); DrvGPIO_ClrBit(E_GPA, 2); } void LCD_data(unsigned char wdata) LCD_DATA=wdata; LCD_RS_HI; LCD_RW_LO; LCD_E_HI; DrvSYS_Delay(1000); LCD_E_LO; void LCD_cmd(unsigned char wdata) { LCD_DATA=wdata; LCD_RS_LO; LCD_RW_LO; LCD_E_HI; DrvSYS_Delay(1000); LCD_E_LO; }

Smpl_GPIO_LCM8x2 void Init_LCM8x2(void) { LCD_DATA=0; DrvSYS_Delay(37);// wait time >40ms after Vcc>4.5V LCD_cmd(0x38); DrvSYS_Delay(37); LCD_cmd(0x0C); LCD_cmd(0x01); DrvSYS_Delay(1520); LCD_cmd(0x06); } void display_xy(uint8_t x,uint8_t y) if(y==1) x+=0x40; x+=0x80; LCD_cmd(x); void display_char(uint8_t x, uint8_t y, unsigned char dat) { display_xy(x,y); LCD_data(dat); } void display_string(uint8_t x,uint8_t y,unsigned char *s) uint8_t i; i=0; while((x+i)<8) LCD_data(*s); s++; i++;

Smpl_GPIO_LCM8x2 main() { unsigned char LcdBuf1[8]= "Nuvoton "; unsigned char LcdBuf2[8]= "CortexM0"; UNLOCKREG(); DrvSYS_SetOscCtrl(E_SYS_XTL12M, 1); // Enable the 12MHz oscillator oscillation DrvSYS_SelectHCLKSource(0); // HCLK clock source. 0: external 12MHz; 4:internal 22MHz RC oscillator LOCKREG(); Init_GPIO(); Init_LCM8x2(); display_string(0,0,LcdBuf1);//顯示第一行,第一列第0位置開始 display_string(0,1,LcdBuf2);//顯示第二行,第二列第0位置開始 }

16x16 LED Matrix Interface Signals: VCC GND P24 P23 P22 P21

16x16 LED Matrix schematic Sample Code : Smpl_GPIO_LED16x16

Smpl_GPIO_LED16x16 // LED Matrix 16x16 // pin description & connection // P24 : CLK to GPA4 // P23 : AB to GPA3 // P22 : RCK to GPA2 // P21 : SRCK to GPA1 // P20 : SER to GPA0 #include <stdio.h> #include "NUC1xx.h" #include "Driver\DrvSYS.h" #include "Driver\DrvGPIO.h" #define GPIO_port E_GPA #define LED16x16_CLK 4 // 74HC164 clock #define LED16x16_AB 3 // 74HC164 AB #define LED16x16_RCK 2 // 74HC595 register clock #define LED16x16_SRCK 1 // 74HC595 shift register clock #define LED16x16_SER 0 // 74HC595 serial in

Smpl_GPIO_LED16x16 void InitLED16x16(void) { DrvGPIO_InitFunction(E_FUNC_GPIO); DrvGPIO_Open(GPIO_port, LED16x16_CLK, E_IO_OUTPUT); DrvGPIO_Open(GPIO_port, LED16x16_AB, E_IO_OUTPUT); DrvGPIO_Open(GPIO_port, LED16x16_RCK, E_IO_OUTPUT); DrvGPIO_Open(GPIO_port, LED16x16_SRCK, E_IO_OUTPUT); DrvGPIO_Open(GPIO_port, LED16x16_SER, E_IO_OUTPUT); // set to default DrvGPIO_ClrBit(GPIO_port, LED16x16_CLK); DrvGPIO_ClrBit(GPIO_port, LED16x16_AB); DrvGPIO_ClrBit(GPIO_port, LED16x16_RCK); DrvGPIO_ClrBit(GPIO_port, LED16x16_SRCK); DrvGPIO_ClrBit(GPIO_port, LED16x16_SER); }

Smpl_GPIO_LED16x16 void CLK(uint8_t level) { if (level==0) DrvGPIO_ClrBit(GPIO_port, LED16x16_CLK); else DrvGPIO_SetBit(GPIO_port, LED16x16_CLK); } void AB(uint8_t level) { if (level==0) DrvGPIO_ClrBit(GPIO_port, LED16x16_AB); else DrvGPIO_SetBit(GPIO_port, LED16x16_AB); } void RCK(uint8_t level) { if (level==0) DrvGPIO_ClrBit(GPIO_port, LED16x16_RCK); else DrvGPIO_SetBit(GPIO_port, LED16x16_RCK); } void SRCK(uint8_t level) { if (level==0) DrvGPIO_ClrBit(GPIO_port, LED16x16_SRCK); else DrvGPIO_SetBit(GPIO_port, LED16x16_SRCK); } void SER(uint8_t level) { if (level==0) DrvGPIO_ClrBit(GPIO_port, LED16x16_SER); else DrvGPIO_SetBit(GPIO_port, LED16x16_SER); }

Smpl_GPIO_LED16x16 void display() { uint8_t i,ia,j,tmp; AB(0); for(i=0;i<16;i++) { CLK(0); RCK(0); SRCK(0); for(ia=2; ia>0; ia--) { tmp = ~ data[(i*2)+ia-1]; // even-byte will shift to Right, odd-byte at Left for(j=0; j<8; j++) { SER(( (tmp>>j) & 0x01)); SRCK(1); } } RCK(1); CLK(1); AB(1);

Smpl_GPIO_LED16x16 int32_t main (void) { uint8_t k; UNLOCKREG(); DrvSYS_SetOscCtrl(E_SYS_XTL12M, 1); //Enable the 12MHz oscillator oscillation DrvSYS_Delay(5000); //Waiting for 12M Xtal stable DrvSYS_SelectHCLKSource(0); // HCLK clock source. 0: external 12MHz; 4:internal 22MHz RC oscillator LOCKREG(); DrvSYS_SetClockDivider(E_SYS_HCLK_DIV, 0); InitLED16x16(); while(1) for(k=0;k<32;k++) data[k]=greenman1[k]; display(); Delay(50000); }

General Disclaimer The Lecture is strictly used for educational purpose. MAKES NO GUARANTEE OF VALIDITY The lecture cannot guarantee the validity of the information found here. The lecture may recently have been changed, vandalized or altered by someone whose opinion does not correspond with the state of knowledge in the relevant fields. Note that most other encyclopedias and reference works also have similar disclaimers. No formal peer review The lecture is not uniformly peer reviewed; while readers may correct errors or engage in casual peer review, they have no legal duty to do so and thus all information read here is without any implied warranty of fitness for any purpose or use whatsoever. Even articles that have been vetted by informal peer review or featured article processes may later have been edited inappropriately, just before you view them. No contract; limited license Please make sure that you understand that the information provided here is being provided freely, and that no kind of agreement or contract is created between you and the owners or users of this site, the owners of the servers upon which it is housed, the individual Wikipedia contributors, any project administrators, sysops or anyone else who is in any way connected with this project or sister projects subject to your claims against them directly. You are being granted a limited license to copy anything from this site; it does not create or imply any contractual or extracontractual liability on the part of Wikipedia or any of its agents, members, organizers or other users. There is no agreement or understanding between you and the content provider regarding your use or modification of this information beyond the Creative Commons Attribution-Sharealike 3.0 Unported License (CC-BY-SA) and the GNU Free Documentation License (GFDL);

General Disclaimer Personality rights Trademarks Any of the trademarks, service marks, collective marks, design rights or similar rights that are mentioned, used or cited in the lectures are the property of their respective owners. Their use here does not imply that you may use them for any purpose other than for the same or a similar informational use as contemplated by the original authors under the CC-BY-SA and GFDL licensing schemes. Unless otherwise stated , we are neither endorsed by nor affiliated with any of the holders of any such rights and as such we cannot grant any rights to use any otherwise protected materials. Your use of any such or similar incorporeal property is at your own risk. Personality rights The lecture may portray an identifiable person who is alive or deceased recently. The use of images of living or recently deceased individuals is, in some jurisdictions, restricted by laws pertaining to personality rights, independent from their copyright status. Before using these types of content, please ensure that you have the right to use it under the laws which apply in the circumstances of your intended use. You are solely responsible for ensuring that you do not infringe someone else's personality rights.