Chap7. LED, LCD 와 7- 세그먼트 켜기및 IIC 통신
LED 를켜기위한순서 1. 프로그램코딩및빌드 ( 헥사파일만들기 ) 2. 프로그램메모리라이팅
M-IDE 빌드해서핵사파일만들기
강의계획 Chap1. 강의계획및디지털논리이론 Chap2. 펌웨어작성을위한 C 언어 I Chap3. 펌웨어작성을위한 C 언어 II Chap4. AT89S52 메모리구조 Chap5. SD-52 보드구성과코드메모리프로그래밍방법 Chap6. 어드레스디코딩 ( 매핑 ) 과어셈블리어코딩방법 Chap7. LED, LCD 와 7- 세그먼트켜기및 IIC 통신 Chap8. 인터럽트와타이머 Chap9. 직렬통신과 PS2 키보드인터페이스 Chap10. 리모콘수신과 RTC 및 Speaker Chap11. AD 컨버터와 DA 컨버터 Chap12. OSD (On-Screen Display)
Keil-C 컴파일러사용하기 (1/5) Project New Atmel AT89C52 확인
Keil-C 컴파일러사용하기 (2/5) Target 1 에서마우스오른쪽버튼후 Option for target target 1
Keil-C 컴파일러사용하기 (3/5)
Keil-C 컴파일러사용하기 (4/5) Source Group 1 에서마우스오른쪽버튼후 Add files to Group Source Group 1 프로그램을작성하신후 Project Build Target or F7
Keil-C 컴파일러사용하기 (5/5) SD-52 Training Board 에있는 CD 나자료실의 AT89S52_HardwareSetting 부분을다운받아서사 용해도됩니다. 기본적인구성이프로그램되어있습니다.
Current (1/2) 소스원이충분할때흐를수있는전류는도선의넓이와비례한다.
Current (2/2) 저항의의해전류량을조절할수있다.
DIODE Symbol of Diode Characteristic of Diode Operation of Diode
LED (1/2) + - R V 5V 2V 3V = = = = 300Ω I 10mA 0.01A
LED (2/2) + - + - + - Case 1 Case 2 Case 3
AT89S52_HardwareSetting Memorymapping.h BYTE xdata LED _at_ 0x0000; BYTE xdata SEG_SIGAL _at_ 0x0100; BYTE xdata SEG_DIGIT _at_ 0x0200; BYTE xdata LCD_WR_COMMAND _at_ 0x0300; BYTE xdata LCD_RD_STATE _at_ 0x0301; BYTE xdata LCD_WR_DATA _at_ 0x0302; BYTE xdata LCD_RD_DATA _at_ 0x0303; BYTE xdata DAC_VALUE _at_ 0x0400; BYTE xdata OUT_CONTROL _at_ 0x0500; void main(void) { BYTE LedVar = 0; Initial_CPU(); while(1){ LED = ~(LedVar++); LongDelay(500); } } Main.c
7-Segment (1/4) Common Anode Type Common cathode Type
7-Segment (2/4) 7-Segment Driving Method Passive Method (Scanning Method) Active Method ( Data Latched Method) MCU Data Latch Latch Latch Latch Latch Enable
7-Segment (3/4) 문제점 : 점유율높다.
7-Segment (4/4) 7- Segment Code Table unsigned char code FND[10] ={ ~(0x01 0x02 0x04 0x08 0x10 0x20), // 0 ~(0x02 0x04), // 1 ~(0x01 0x02 0x40 0x10 0x08),// 2 ~(0x01 0x02 0x40 0x04 0x08),// 3 ~(0x20 0x40 0x02 0x04), // 4 ~(0x01 0x20 0x40 0x04 0x08),// 5 ~(0x20 0x10 0x40 0x04 0x08),// 6 ~(0x20 0x01 0x02 0x04), // 7 ~(0x01 0x02 0x04 0x40 0x08 0x10 0x20), // 8 ~(0x20 0x01 0x02 0x40 0x04), // 9 };
CLCD (1/9) CLCD Interface Part
CLCD (2/9) - 4bit, 8bit interface - 5X8 dots or 5X7 dots character font - Display Data RAM (DDRAM), Character Generator ROM (CGROM) and CGRAM - Display clear, cursor home, display on/off, cursor on/off, display character blink, cursor shift, display shift. - instruction register (IR) and an data register (DR) By RS and R/W input signals, these two registers can be selected. (if RS = 0 then IR, else DR)
ASCII Table 과호환 : ex) A = 0x41 printf( A ); CLCD (3/9)
CLCD (4/9) Write Timing
CLCD (5/9) Read Timing
CLCD (6/9) Clear Display : 전체화면을지우고 DDRAM 어드레스를 0으로 clear한후커서를 home 위치로옮긴다. Return Home : 커서를홈으로위치시킨다. Entry Mode Set : I/D=1: Increment the DDRAM address, I/D=0, Decrement the DDRAM address S = 1 : shifts the entire display, S=0, the display does not shift. Display on/off control : D = 1 : Displaly On, D = 0 : Display Off C = 1 :Cursor On, C = 0 : Cursor Off B = 1 : Cursor Blink On, B = 0 : Cursor Blink Off
CLCD (7/9) Cursor or display shift : 00: Shifts the cursor position to the left, 01: Shifts the cursor position to the right : 10: Shifts the entire display to the left. 11: Shifts the entire display to the right. Function set DL:Sets the interface data length. 1: Data are sent or received in 8-bit lengths (DB7 to DB0) 0: Data are sent or received in 4-bit lengths (DB7 to DB4) * 4-bit length is selected, data must be sent or received twice. N:Sets the number of display lines. 1 : 2 행 0 : 1 행 F:Sets the character font. 1 : 5 X 11 0 : 5 X 8 Read busy flag and address
CLCD (8/9) LCD 초기화 lcd_command_write(0x38); lcd_command_write(0x08); lcd_command_write(0x01); lcd_command_write(0x06); lcd_command_write(0x0c); LCD Initial 이성공하면 LCD 위에나타나는바가없어진다.
CLCD (9/9) Programming Method 1. command write와 display write 함수를만들어라 2. 쉬운접근을위한 String 함수를만들어라. ex) LcdString(BYTE line, char *str) LcdString(0x80, Smartdisplay World ) void LcdString(BYTE line, char *str) { BYTE index; BYTE character; lcd_command_write(line); // LCD command : cursor position index = 0; character = str[index]; while(character!= '\0') { lcd_char_display(character); // LCD character display index++; character = str[index]; } }
IIC Protocol(1/7) Introduction to IIC(I2C) Philips originally developed a simple bi-directional 2-wire, Serial Data (SDA) and Serial Clock (SCL) bus for inter-ic control. A complete system usually consists of at least one microcontroller (Master) and other peripheral devices (Slave). IIC Protocol is made up start condition, memory addressing bit data input, acknowledge bit, and stop condition.
IIC Protocol(2/7) The IIC-BUS Concept Micro Controller Video Processor Audio Processor ADC SDA SCL Memory OSD LCD DRIVER Example of IIC-Bus Application Two wires, serial data (SDA) and serial clock (SCL), carry information between devices connected to the bus. Each device has a its own address. (ex, Memory : 0xA0, Audio Processor: 0xA8) It appears that Micro-controller is the master device, the others are slave devices.
IIC Protocol(3/7) General Characteristics VDD Pull-Up Resistors SDA(Serial Data Line) SCL(Serial Clock Line) SCLK1 OUT DATA1 OUT SCLK1 OUT DATA1 OUT SCLK IN DATA IN SCLK IN DATA IN Device 1 Device 2 Connection of device to the IIC-bus Both SDA and SCL are bi-directional lines, connected to Pull-up resistors. When the bus is free, both line is HIGH. The output stage must have an open-drain or open-collector to perform to Wired-AND function
IIC Protocol(4/7) Start and Stop Conditions Start Condition : A HIGH to LOW transition on the SDA line while SCL line is HIGH. Stop Condition : A LOW to HIGH transition on the SDA line while SCL line is HIGH. Data Validity The data on the SDA line must be stable during the HIGH period of clock.
IIC Protocol(5/7) Write Operation Byte Write Page Write
IIC Protocol(6/7) Read Operation Current Address Read Random Read
IIC Protocol(7/7) Read Operation Sequential Read
Tip (1/2)
Tip (2/2) #define SetRtcSCLK (P1 = 0x04) #define SetSCL (OUT_CONTRL_REGISTER = 0x20); OUT_CONTROL = OUT_CONTRL_REGISTER P1 : Register 개념으로비트단위로제어가가능 OUT_CONTROL : 외부번지로비트단위로제어불능 ( 저장기능없음 ) 따라서비트단위로제어를하기위해서는저장기능을갖는레지스터를만들어줘야함
숙제 1. 지난주에어셈으로작성하였던 LED 프로그램 C 로작성 2. 7-Segment 0~9999 까지카운팅하기 3. CLCD 의첫번째열에자기이름쓰기 4. CLCD 에 7-Segment 와같은숫자나오게하기 5. EEPROM(24C04) 을가지고 Byte Write, Page Write, Current Address Read, Random Read, Sequential Read 구현하기 (24C04 는 SD-52 보드에실장되어있음 ) 회로도보는연습을하자. 데이터쉬트보는연습을하자. 다음시간에는인터럽트와타이머를학습합니다.