chap7. led, lcd와7-세그먼트 켜기및iic...
TRANSCRIPT
Chap7. LED, LCD와 7-세그먼트켜기 및 IIC 통신
http://www.smartdisplay.co.kr
http://www.smartdisplay.co.kr
LED를 켜기 위한 순서
1. 프로그램 코딩 및 빌드 (헥사파일 만들기)
2. 프로그램 메모리 라이팅
http://www.smartdisplay.co.kr
M-IDE 빌드 해서 핵사 파일 만들기
http://www.smartdisplay.co.kr
강의 계획
Chap1. 강의계획및 디지털 논리 이론Chap2. 펌웨어 작성을 위한 C언어 IChap3. 펌웨어 작성을 위한 C언어 IIChap4. AT89S52 메모리 구조Chap5. SD-52보드 구성과 코드 메모리 프로그래밍 방법Chap6. 어드레스 디코딩(매핑)과 어셈블리어 코딩 방법Chap7. LED, LCD와 7-세그먼트 켜기 및 IIC 통신Chap8. 인터럽트와 타이머Chap9. 직렬통신과 PS2 키보드 인터페이스Chap10. 리모콘 수신과 RTC 및 SpeakerChap11. AD컨버터와 DA컨버터Chap12. OSD (On-Screen Display)
http://www.smartdisplay.co.kr
Keil-C 컴파일러 사용하기 (1/5)
Project New
Atmel AT89C52
확인
http://www.smartdisplay.co.kr
Keil-C 컴파일러 사용하기 (2/5)
Target 1에서 마우스 오른쪽 버튼 후Option for target ‘target 1’
http://www.smartdisplay.co.kr
Keil-C 컴파일러 사용하기 (3/5)
http://www.smartdisplay.co.kr
Keil-C 컴파일러 사용하기 (4/5)
Source Group 1에서 마우스 오른쪽 버튼 후Add files to Group ‘ Source Group 1’
프로그램을 작성 하신후Project Build Target or F7
http://www.smartdisplay.co.kr
Keil-C 컴파일러 사용하기 (5/5)
SD-52 Training Board에 있는 CD나 자료실의
AT89S52_HardwareSetting 부분을 다운 받아서 사
용해도 됩니다.
기본적인 구성이 프로그램 되어 있습니다 .
http://www.smartdisplay.co.kr
Current (1/2)
소스원이 충분할 때 흐를 수 있는 전류는 도선의 넓이와 비례한다.
http://www.smartdisplay.co.kr
Current (2/2)
저항의 의해 전류량을 조절 할 수 있다.
http://www.smartdisplay.co.kr
DIODE
Symbol of Diode Characteristic of Diode
Operation of Diode
http://www.smartdisplay.co.kr
LED (1/2)
+-
Ω==−
== 30001.03
1025
AV
mAVV
IVR
http://www.smartdisplay.co.kr
LED (2/2)
Case 1 Case 2 Case 3
+-
+-
+-
http://www.smartdisplay.co.kr
AT89S52_HardwareSettingMemorymapping.hBYTE 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
http://www.smartdisplay.co.kr
7-Segment (1/4)
Common Anode Type Common cathode Type
http://www.smartdisplay.co.kr
7-Segment (2/4)
7-Segment Driving Method
MCULatch Latch Latch Latch
Data
Latch Enable
Passive Method (Scanning Method) Active Method ( Data Latched Method)
http://www.smartdisplay.co.kr
7-Segment (3/4)
문제점 : 점유율 높다.
http://www.smartdisplay.co.kr
7-Segment (4/4)
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
};
7- Segment Code Table
http://www.smartdisplay.co.kr
CLCD (1/9)
CLCD Interface Part
http://www.smartdisplay.co.kr
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)
http://www.smartdisplay.co.kr
ASCII Table과 호환 : ex) A = 0x41 printf(“A”);
CLCD (3/9)
http://www.smartdisplay.co.kr
CLCD (4/9)
Write Timing
http://www.smartdisplay.co.kr
CLCD (5/9)
Read Timing
http://www.smartdisplay.co.kr
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 OffB = 1 : Cursor Blink On, B = 0 : Cursor Blink Off
http://www.smartdisplay.co.kr
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 110 : 5 X 8
Read busy flag and address
http://www.smartdisplay.co.kr
CLCD (8/9)
lcd_command_write(0x38);
lcd_command_write(0x08);
lcd_command_write(0x01);
lcd_command_write(0x06);
lcd_command_write(0x0C);
LCD Initial이 성공하면 LCD 위에 나타나는 바가 없어진다.
LCD 초기화
http://www.smartdisplay.co.kr
CLCD (9/9)
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 displayindex++;character = str[index];
}}
Programming Method
http://www.smartdisplay.co.kr
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.
http://www.smartdisplay.co.kr
IIC Protocol(2/7)The IIC-BUS Concept
Micro Controller
Video Processor
AudioProcessor
Memory OSD LCD DRIVER
ADC
SDASCL
Example of IIC-Bus Application
Two wires, serial data (SDA) and serial clock (SCL), carry information betweendevices 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.
http://www.smartdisplay.co.kr
IIC Protocol(3/7)
SCLK1OUT
DATA1OUT
SCLKIN
DATAIN
SCLK1OUT
DATA1OUT
SCLKIN
DATAIN
SDA(Serial Data Line)SCL(Serial Clock Line)
Device 1 Device 2
Pull-UpResistors
VDD
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
General Characteristics
http://www.smartdisplay.co.kr
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.
http://www.smartdisplay.co.kr
IIC Protocol(5/7)Write Operation
Byte Write
Page Write
http://www.smartdisplay.co.kr
IIC Protocol(6/7)
Read Operation
Current Address Read
Random Read
http://www.smartdisplay.co.kr
IIC Protocol(7/7)Read Operation
Sequential Read
http://www.smartdisplay.co.kr
Tip (1/2)
http://www.smartdisplay.co.kr
Tip (2/2)
#define SetRtcSCLK (P1 |= 0x04)
#define SetSCL (OUT_CONTRL_REGISTER |= 0x20); OUT_CONTROL = OUT_CONTRL_REGISTER
P1 : Register 개념으로 비트 단위로 제어가 가능
OUT_CONTROL : 외부 번지로 비트 단위로 제어 불능 (저장기능 없음)따라서 비트 단위로 제어를 하기 위해서는 저장 기능을 갖는 레지스터를 만들어 줘야함
http://www.smartdisplay.co.kr
숙제
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 보드에 실장 되어 있음)
회로도 보는 연습을 하자.
데이터쉬트 보는 연습을 하자.
다음 시간에는 인터럽트와 타이머를 학습합니다.