Digital Watch 구현
description
Transcript of Digital Watch 구현
Digital Watch Digital Watch 구현구현
Lecture #13Lecture #13
모바일컴퓨터특강 2
Digital Watch – Design Specification VHDL 의 입출력 설계 사양
입력 : Clock : 12MHz Key 3 개 : RESET SW, SET SW, INC SW
출력 : LCD Interface : E, RS, RW, D0, D1, D2, D3, D4,
D5, D6, D7
모바일컴퓨터특강 3
Digital Watch – Design Specification
RESET SET INC
입력장치 ( Input Device ) 3 개의 푸시 버튼 스위치를 사용 RESET SW, SET SW, INC SW 각각의 스위치는 눌러질 경우에 1 을 출력하고 , 평상시에는 0
을 출력하는 구조
모바일컴퓨터특강 4
Digital Watch – Design Specification 출력장치 (Output Device)
Character LCD 16 문자 2 줄
열위치 ->
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
1 행 -> 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13
2 행 -> 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 51 52 53
D.D.RAM 의 주소
모바일컴퓨터특강 5
Digital Watch – Design Specification
Digital Watch 동작 설계
(1) 초기 POWER ON 시 RESET 상태 ( = Initial_State )
- 초기에 표시되는 값은 AM 12 : 00 임 - AM 12 00 전체가 0.5 초 간격으로 깜박거림 - SET KEY 가 눌러지면 시간 수정모드의 처음인 TIME AM/PM
SETTING MODE 로 이동
D I G I T A L W A T C H
T I M E : A M 1 2 : 0 0
모바일컴퓨터특강 6
Digital Watch – Design Specification
(2) 시간 수정모드 ① TIME AM/PM SETTING MODE ( = Time_AmPm_Set_State )
- 초기상태는 AM/PM 위치의 LED 가 0.5 초 간격으로 깜박이며 다른 부분은 DISPLAY ON 됨
- INC KEY 에 의해 AM/PM 이 반전되어 나타남 - SET KEY 를 누르면 TIME HOUR SETTING MODE 로 이동
② TIME HOUR SETTING MODE ( = Time_Hour_Set_State )
- 현재의 HOUR 을 나타내는 LED 가 0.5 초 간격으로 깜박임 - INC KEY 에 의해 1 씩 증가함 12 1 2 3 4 5 6 7 8 9 10 11 12 .. - SET KEY 를 누르면 TIME MIN HIGH SETTING MODE 로 이동
Set Key 나 Inc Key 2 가지 입력 중 어느 하나의 Key 라도 눌러지면 그 시점에 동기를 맞춰 켜짐부터 깜박임을 다시 시작해야 한다 .=> 이런 디스플레이 방식이 시간 수정 시에 자연스럽다 .
Set Key 나 Inc Key 2 가지 입력 중 어느 하나의 Key 라도 눌러지면 그 시점에 동기를 맞춰 켜짐부터 깜박임을 다시 시작해야 한다 .=> 이런 디스플레이 방식이 시간 수정 시에 자연스럽다 .
D I G I T A L W A T C H
T I M E : A M 1 2 : 0 0
D I G I T A L W A T C H
T I M E : P M 1 2 : 0 0
모바일컴퓨터특강 7
Digital Watch – Design Specification
(2) 시간 수정모드 ③ TIME MIN HIGH SETTING MODE ( = Time_Min_High_Set_State )
- 현재의 분의 HIGH 를 나타내는 LED 가 0.5 초 간격으로 깜박임 - INC KEY 에 의해 1 씩 증가함 0 1 2 3 4 5 0 .. - SET KEY 를 누르면 TIME MIN LOW SETTING MODE 로 이동
④ TIME MIN LOW SETTING MODE ( = Time_Min_Low_Set_State )
- 현재의 분의 LOW 를 나타내는 LED 가 0.5 초 간격으로 깜박임 - INC KEY 에 의해 1 씩 증가함 0 1 2 3 4 5 0 .. - SET KEY 를 누르면 NORMAL TIME MODE 로 이동
D I G I T A L W A T C H
T I M E : P M 2 : 0 0
D I G I T A L W A T C H
T I M E : P M 2 : 3 0
모바일컴퓨터특강 8
Digital Watch – Design Specification
(3) NORMAL TIME MODE ( = Normal_Time_State )
- 현재 진행되는 시간을 나타냄 - SET KEY 가 눌러지면 시간 수정모드의 처음인 TIME AM/PM
SETTING MODE 로 이동
D I G I T A L W A T C H
T I M E : P M 2 : 3 5 : 0 0
모바일컴퓨터특강 9
Digital Watch – 전체 회로
이 부분을 VHDL 로 설계함 .
이 부분을 VHDL 로 설계함 . CharacterL
CD 사용 .CharacterLCD 사용 .
LCD 의 밝기 조절
회로 .
LCD 의 밝기 조절
회로 .
모바일컴퓨터특강 10
Digital Watch – Top Level 구성
모바일컴퓨터특강 11
Digital Watch – Top Level 구성
이 블록을 제외하고 나머지는 Digital
Watch – FND Interface 와
같음 .
이 블록을 제외하고 나머지는 Digital
Watch – FND Interface 와
같음 .
LCD Interface
부
LCD Interface
부
BCD -> ASCII 변환부
BCD -> ASCII 변환부
모바일컴퓨터특강 12
Digital Watch – Top Level Entity (1)
-- purpose : clock top block-- ver 2 : LCD interfaceLIBRARY IEEE;USE IEEE.std_logic_1164.all;
entity clocklcd isport( clk : in std_logic; reset_sw : in std_logic; set_sw : in std_logic;
inc_sw : in std_logic; --;e : out std_logic;rw : out std_logic;rs : out std_logic;data : out std_logic_vector(7 downto 0)
);end clocklcd;
Architecture a of clocklcd issignal set_button, inc_button : std_logic;signal set_shot, inc_shot : std_logic;signal reset, Hz100 : std_logic;signal state : std_logic_vector(3 downto 0);signal time_set_mode : std_logic;
-- time counters for 7 segmentsignal time_ampm : std_logic;signal time_hour_high : std_logic;signal time_hour_low : std_logic_vector(3 downto 0);signal time_min_high : std_logic_vector(2 downto 0);signal time_min_low : std_logic_vector(3 downto 0);signal time_sec_high : std_logic_vector(2 downto 0);signal time_sec_low : std_logic_vector(3 downto 0);signal led_blink : std_logic;signal buzzer_blink : std_logic; -- for 0.5 sec buzer blink
모바일컴퓨터특강 13
Digital Watch – Top Level Entity (2)
signal initial_state : std_logic;signal time_ampm_set_state : std_logic;signal time_hour_set_state : std_logic;signal time_min_high_set_state : std_logic;signal time_min_low_set_state : std_logic;signal normal_time_state : std_logic;
signal s_select_hour_high : std_logic; -- for hour_high=0 : display Off;
signal LCD_time_ampm_ap : std_logic_vector(7 downto 0);signal LCD_time_ampm_m : std_logic_vector(7 downto 0);signal LCD_time_hour_high : std_logic_vector(7 downto 0);signal LCD_time_hour_low : std_logic_vector(7 downto 0);signal LCD_time_min_high : std_logic_vector(7 downto 0);signal LCD_time_min_low : std_logic_vector(7 downto 0);signal LCD_time_sec_high : std_logic_vector(7 downto 0);signal LCD_time_sec_low : std_logic_vector(7 downto 0);signal LCD_time_sec_colon : std_logic_vector(7 downto 0);
component statemachine port ( clk : in std_logic; reset : in std_logic; set_shot : in std_logic;
initial_state : out std_logic;time_ampm_set_state : out std_logic;time_hour_set_state : out std_logic;time_min_high_set_state : out std_logic;time_min_low_set_state : out std_logic;normal_time_state : out std_logic;
time_set_mode : out std_logic);end component;
모바일컴퓨터특강 14
Digital Watch – Top Level Entity (3)
component timecount port( clk : in std_logic; reset : in std_logic; inc_shot : in std_logic; set_shot : in std_logic;
initial_state : in std_logic;time_ampm_set_state : in std_logic;time_hour_set_state : in std_logic;time_min_high_set_state : in std_logic;time_min_low_set_state : in std_logic;normal_time_state : in std_logic;
-- time counters for 7 segment time_ampm : buffer std_logic; time_hour_high : buffer std_logic; time_hour_low : buffer std_logic_vector(3 downto 0); time_min_high : buffer std_logic_vector(2 downto 0); time_min_low : buffer std_logic_vector(3 downto 0); time_sec_high : buffer std_logic_vector(2 downto 0); time_sec_low : buffer std_logic_vector(3 downto 0); buzzer_blink : buffer std_logic -- for 0.5 sec buzer blink);end component;
component ledblink port( clk : in std_logic; reset : in std_logic; set_shot : in std_logic; inc_shot : in std_logic;
initial_state : in std_logic;time_set_mode : in std_logic;
led_blink : buffer std_logic);end component;
모바일컴퓨터특강 15
Digital Watch – Top Level Entity (4)
component LCD_IF port(
clk : in std_logic; -- 10KHz : 0.1msec = 100usecresetb : in std_logic;
-- LCD input : time informationLCD_time_ampm_ap : in std_logic_vector(7 downto 0);LCD_time_ampm_m : in std_logic_vector(7 downto 0);LCD_time_hour_high : in std_logic_vector(7 downto 0);LCD_time_hour_low : in std_logic_vector(7 downto 0);LCD_time_min_high : in std_logic_vector(7 downto 0);LCD_time_min_low : in std_logic_vector(7 downto 0);LCD_time_sec_high : in std_logic_vector(7 downto 0);LCD_time_sec_low : in std_logic_vector(7 downto 0);
LCD_time_sec_colon : in std_logic_vector(7 downto 0);e : out std_logic;rw : out std_logic;rs : out std_logic;data : out std_logic_vector(7 downto 0));
end component;
component Hz100ctrl port( clk,nclr : in std_logic; Hz100 : out std_logic);end component;
component shotpulse port( clk : in std_logic; reset : in std_logic; d : in std_logic; rising_shot : out std_logic);end component;
모바일컴퓨터특강 16
Digital Watch – Top Level Entity (5)component ToLCDBlink port(
initial_state : in std_logic;time_ampm_set_state : in std_logic;time_hour_set_state : in std_logic;time_min_high_set_state : in std_logic;time_min_low_set_state : in std_logic;normal_time_state : in std_logic;
led_blink : in std_logic;
-- time clock time_ampm : in std_logic; time_hour_high : in std_logic; time_hour_low : in std_logic_vector(3 downto 0); time_min_high : in std_logic_vector(2 downto 0); time_min_low : in std_logic_vector(3 downto 0); time_sec_high : in std_logic_vector(2 downto 0); time_sec_low : in std_logic_vector(3 downto 0);
-- LCD input : time information LCD_time_ampm_ap : out std_logic_vector(7 downto 0); LCD_time_ampm_m : out std_logic_vector(7 downto 0); LCD_time_hour_high : out std_logic_vector(7 downto 0); LCD_time_hour_low : out std_logic_vector(7 downto 0); LCD_time_min_high : out std_logic_vector(7 downto 0); LCD_time_min_low : out std_logic_vector(7 downto 0); LCD_time_sec_high : out std_logic_vector(7 downto 0); LCD_time_sec_low : out std_logic_vector(7 downto 0);
LCD_time_sec_colon : out std_logic_vector(7 downto 0));end component;
모바일컴퓨터특강 17
Digital Watch – Top Level Entity (6)
beginU1: statemachine port map( Hz100, reset, set_shot, initial_state, time_ampm_set_state,
time_hour_set_state,time_min_high_set_state, time_min_low_set_state, normal_time_state, time_set_mode);
U2: timecount port map( Hz100, reset, inc_shot, set_shot, initial_state, time_ampm_set_state, time_hour_set_state, time_min_high_set_state, time_min_low_set_state, normal_time_state,
time_ampm, time_hour_high, time_hour_low, time_min_high, time_min_low, time_sec_high, time_sec_low, buzzer_blink );
U3: ledblink port map( Hz100, reset, set_shot, inc_shot, initial_state, time_set_mode, led_blink);
U4 :Hz100ctrl port map( clk,reset,Hz100);
U5: shotpulse port map( Hz100, reset, set_button, set_shot );U6: shotpulse port map( Hz100, reset, inc_button, inc_shot );
reset <= not(reset_sw);set_button <= (set_sw) and not(inc_sw);inc_button <= not(set_sw) and inc_sw;
U7: ToLCDBlink port map( initial_state, time_ampm_set_state, time_hour_set_state, time_min_high_set_state, time_min_low_set_state, normal_time_state, led_blink, time_ampm, time_hour_high, time_hour_low, time_min_high, time_min_low, time_sec_high, time_sec_low, LCD_time_ampm_ap, LCD_time_ampm_m, LCD_time_hour_high, LCD_time_hour_low, LCD_time_min_high, LCD_time_min_low, LCD_time_sec_high, LCD_time_sec_low, LCD_time_sec_colon);
U8: LCD_IF port map(clk, reset, LCD_time_ampm_ap, LCD_time_ampm_m, LCD_time_hour_high,LCD_time_hour_low, LCD_time_min_high, LCD_time_min_low, LCD_time_sec_high, LCD_time_sec_low, LCD_time_sec_colon, e, rw, rs, data );
end a;
모바일컴퓨터특강 18
Digital Watch - Shot Pulse Gen.
100Hz 100Hz Clk 에 비동기
입력
Clk 에 비동기
입력 Clk 에 동기
됨
Clk 에 동기
됨
입력신호가 1 로 들어오면
100Hz 의 1주기동안 1 인
신호
입력신호가 1 로 들어오면
100Hz 의 1주기동안 1 인
신호
외부에서 입력되는 키의 신호는 모두 클럭 100Hz 에 비동기인 신호 실제 회로 내부에서 필요한 신호는 동기신호 이므로 동기처리 후 Shot
Pulse 를 만들어야 한다
모바일컴퓨터특강 19
Digital Watch - Shot Pulse Gen.
-- purpose : rising shot pulse generatorLIBRARY IEEE;USE IEEE.std_logic_1164.all;
entity shotpulse isport( clk : in std_logic; reset : in std_logic; d : in std_logic; rising_shot : out std_logic);end shotpulse;
architecture a of shotpulse issignal qa,qb : std_logic;begin
process(clk,reset)begin
if(reset='0') then qa<='0';qb<='0'; elsif(clk'event and clk='1') then qa<= d; qb<=qa; end if;
end process;
rising_shot <= qa and not(qb);end a;
모바일컴퓨터특강 20
Digital Watch - 100Hz Gen. 12MHz Clock(=clk) 으로부터 1/100 초인 100Hz(=Hz100) 을 만드는
회로
100Hz 는 1/100초이므로 Stop
Watch 의 1/100초를 카운트하는데 사용되는 클럭으로
사용된다 . TimeControl 블록과
KeyIF 의 클럭으로 사용됨
100Hz 는 1/100초이므로 Stop
Watch 의 1/100초를 카운트하는데 사용되는 클럭으로
사용된다 . TimeControl 블록과
KeyIF 의 클럭으로 사용됨
10KHz:100Hz=100:1
그러므로 10KHz 가 100 주기 발생할 때 100Hz 는 1 주기
발생하면 된다 .
10KHz:100Hz=100:1
그러므로 10KHz 가 100 주기 발생할 때 100Hz 는 1 주기
발생하면 된다 .
10KHz 10KHz
모바일컴퓨터특강 21
Digital Watch - 100Hz Gen.
library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all;entity Hz100ctrl is
port( clk, nclr : in std_logic; Hz100 : out std_logic);end Hz100ctrl;architecture a of Hz100ctrl is
signal cnt : std_logic_vector(5 downto 0);signal sHz100 : std_logic;
Begin
process(nclr,clk)begin
if( nclr='0') thencnt <="000000";
elsif(clk'event and clk='1') thenif(cnt=49) then
cnt <= "000000";else
cnt <= cnt+'1';end if;
end if;end process;
process(nclr,clk)begin
if( nclr='0') thensHz100 <='0';
elsif(clk'event and clk='1') thenif(cnt=49) then
sHz100 <= not sHz100;end if;
end if;end process;Hz100 <= sHz100;
end a;
Modulo 50
Counter
Modulo 50
Counter
Cnt=49일 때마다
Hz100 를 Toggle
함
Cnt=49일 때마다
Hz100 를 Toggle
함
Clk=10KHz Clk=10KHz
Hz100=100Hz
Hz100=100Hz
모바일컴퓨터특강 22
Digital Watch - Mode Control(Flow)
S0
S1
S2
S3
S4
1
1
1
1
1
0
0
0
0
0 상태도 설명 :1. 초기에 전원이 인가되면 S0 에서 부터 시작한다 .
2. Set_Shot 신호가 1 이 입력될 때마다 다음 상태로 천이 되며 , 0 입력이면 상태를 그대로 유지한다 .
3. 시간 수정모드의 마지막 상태인 S4 에서 Set_Shot 이 1 로 들어오면 , 상태는 정상적인 시간이 진행되는 S5 로 천이 된다 .
4. S5 상태에서 Set_Shot 이 1 로 입력되면 상태는 시간 수정모드의 시작인 S1 으로 다시 천이 되고 AM/PM 값의 수정을 시작한다 .
상태도 설명 :1. 초기에 전원이 인가되면 S0 에서 부터 시작한다 .
2. Set_Shot 신호가 1 이 입력될 때마다 다음 상태로 천이 되며 , 0 입력이면 상태를 그대로 유지한다 .
3. 시간 수정모드의 마지막 상태인 S4 에서 Set_Shot 이 1 로 들어오면 , 상태는 정상적인 시간이 진행되는 S5 로 천이 된다 .
4. S5 상태에서 Set_Shot 이 1 로 입력되면 상태는 시간 수정모드의 시작인 S1 으로 다시 천이 되고 AM/PM 값의 수정을 시작한다 .
S5
1
0
Input : Set_Shot
Set_Shot 은 입력 스위치인 Set Key 를 누르면 클럭의 1 주기 동안만 1 이 되는 Shot Pulse 임 .
Input : Set_Shot
Set_Shot 은 입력 스위치인 Set Key 를 누르면 클럭의 1 주기 동안만 1 이 되는 Shot Pulse 임 .
상태는 전부 6 개로 나누어짐 .
S0 : Initial State
S1 : AM/PM Setting State
S2 : Hour Setting State
S3 : Minute High Setting State
S4 : Minute Low Setting State
S5 : Normal Time State
상태는 전부 6 개로 나누어짐 .
S0 : Initial State
S1 : AM/PM Setting State
S2 : Hour Setting State
S3 : Minute High Setting State
S4 : Minute Low Setting State
S5 : Normal Time State
S1, S2, S3, S4는 시간
수정 Mode
임 .
S1, S2, S3, S4는 시간
수정 Mode
임 .
모바일컴퓨터특강 23
Digital Watch - Mode Control(Flow)
-- purpose : mode control. ver2LIBRARY IEEE; USE IEEE.std_logic_1164.all; USE
IEEE.std_logic_unsigned.all;entity statemachine isport( clk : in std_logic; reset : in std_logic; set_shot : in std_logic;
initial_state : out std_logic; time_ampm_set_state : out std_logic; time_hour_set_state : out std_logic; time_min_high_set_state: out std_logic; time_min_low_set_state : out std_logic; normal_time_state : out std_logic;
time_set_mode : out std_logic);end statemachine;
architecture a of statemachine issignal cnt : std_logic_vector(2 downto 0);signal decout : std_logic_vector(5 downto 0);begin
출력신호 : 각각의 상태를 출력함
출력신호 : 각각의 상태를 출력함
Time_set_mode 는
시간수정모드인 경우에 1 을 출력함 .
Time_set_mode 는
시간수정모드인 경우에 1 을 출력함 .
모바일컴퓨터특강 24
Digital Watch - Mode Control(Flow)
process(clk,reset)begin if(reset='0') then cnt <= "000"; elsif(clk'event and clk='1') then
if(set_shot ='1') thenif(cnt="101") then
cnt <= "001"; else cnt <= cnt+'1';
end if; end if; end if;end process ;process(cnt)begin
case cnt iswhen "000" =>
decout <= "100000";when "001" =>
decout <= "010000";when "010" =>
decout <= "001000";when "011" =>
decout <= "000100";when "100" =>
decout <= "000010";when others =>
decout <= "000001";end case;
end process ;
Counter 를 이용한 State
Machine 구현
Counter 를 이용한 State
Machine 구현
Cnt 의 값을 Decoding
Cnt 의 값을 Decoding
모바일컴퓨터특강 25
Digital Watch - Mode Control(Flow)
initial_state <= decout(5);time_ampm_set_state <= decout(4);time_hour_set_state <= decout(3);time_min_high_set_state <= decout(2);time_min_low_set_state<= decout(1);normal_time_state <= decout(0);
time_set_mode <= decout(4) or decout(3) or decout(2) or decout(1) ;
end a;
각각의 State를 출력함 .
각각의 State를 출력함 .
Time_set_mode 는
시간수정모드인 경우에 1 을
출력함 .
Time_set_mode 는
시간수정모드인 경우에 1 을
출력함 .
모바일컴퓨터특강 26
Digital Watch - Time Control
time_hour_low=9
time_hour_low=2
time_hour_high=1
time_hour_low <= 0 time_hour_high <= 1
time_hour_low <= 1 time_hour_high <= 0
time_hour_low ++
1
0
0
0
1
1
state=time_hour_set_state
1
time_min_high=5
time_min_high <= 0
time_min_high ++
0
state=time_min_high_set_state
1
time_min_low=9
time_min_low <= 0
time_min_low ++
1
1
0
state= time_min_low_set_state
time_ampm <= not(time_ampm)
state=time_ampm_set_state
time_set_mode
0
0
0
0
1
inc_shot
0
1
11
inc_shot0
1 1
inc_shot0
1
inc_shot
0
1
1
시간 수정모드에서의 Flow시간 수정모드에서의 Flow
AM/PM
수정모드
Hour
수정모드분 10 의자리
수정모드
분 1 의자리수정모드
9 시
12 시 50 분9 분
모바일컴퓨터특강 27
Digital Watch - Time Control
time_cnt=half_sec & buzzer_blink=1
time_sec_low=9
1
0
time_sec_low++
time_sec_high=5
0
1
time_sec_low<=0 time_sec_high ++
time_min_low=9
0
1
time_min_high=5
0
1
1
time_hour_low=90
1
time_sec_low<= 0time_sec_high<= 0time_min_low<= 0 time_min_high<= 0time_hour_low<= 0
time_hour_high<= 1
time_min_low=2 &time_min_high=1
0
1
time_sec_low<= 0time_sec_high <= 0time_min_low <= 0 time_min_high <= 0time_hour_low ++time_ampm <= not(time_ampm)
time_hour_low=1 &time_hour_high=1
1
time_sec_low<= 0time_sec_high <= 0time_min_low <= 0time_min_high <= 0time_hour_low <= 1time_hour_high<= 0
time_sec_low<=0 time_sec_high<=0
time_min_low<=0time_min_high++
time_sec_low<=0 time_sec_high<=0
time_min_low ++
0state=initial_state
time_cnt, buzzer_blink setting mode
0
0
time_cnt=half_cnt1
time_cnt ++
1
time_cnt <= 0buzzer_blinlk<=not(buzer_blink)
0
Normal_Time_State
time_sec_low <= 0 time_sec_high <= 0 time_min_low <= 0 time_min_high <= 0 time_hour_low ++
시간진행모드에서의 Flow시간진행모드에서의 Flow
1 초 = time_Cnt=25 & Buzzer_Blink=1
1 초 = time_Cnt=25 & Buzzer_Blink=1
9 초
59 초
59 분 59 초
9 분 59 초
9 시 59 분 59 초12 시 59 분 59 초
11 시 59 분 59 초
모바일컴퓨터특강 28
Digital Watch - Time Control
-- purpose : time counter control(revised 3)LIBRARY IEEE;USE IEEE.std_logic_1164.all;USE IEEE.std_logic_unsigned.all;entity timecount isport( clk : in std_logic; reset : in std_logic; inc_shot : in std_logic; set_shot : in std_logic;
initial_state : in std_logic;time_ampm_set_state : in std_logic;time_hour_set_state : in std_logic;time_min_high_set_state : in std_logic;time_min_low_set_state : in std_logic; normal_time_state : in std_logic;
-- time counters for 7 segment time_ampm : buffer std_logic; time_hour_high : buffer std_logic; time_hour_low : buffer std_logic_vector(3 downto 0); time_min_high : buffer std_logic_vector(2 downto 0); time_min_low : buffer std_logic_vector(3 downto 0); time_sec_high : buffer std_logic_vector(2 downto 0); time_sec_low : buffer std_logic_vector(3 downto 0); buzzer_blink : buffer std_logic -- for 0.5 sec buzer blink);end timecount;
모바일컴퓨터특강 29
Digital Watch - Time Control
architecture a of timecount isCONSTANT AM : std_logic := '0';CONSTANT PM : std_logic := '1';signal time_cnt : std_logic_vector(5 downto 0); -- for 0.5 sec countsignal sec_high5,sec_low9 : std_logic;signal min_high5,min_low9 : std_logic;signal hour_high1,hour_low1,hour_low2,hour_low9 : std_logic;signal sec_59 : std_logic;signal min_sec_959 : std_logic;signal min_sec_5959 : std_logic;signal hour_min_sec_95959 : std_logic;signal hour_min_sec_115959 : std_logic;signal hour_min_sec_125959 : std_logic;signal hour_12 : std_logic;signal one_sec : std_logic;
beginsec_high5 <= time_sec_high(2) and time_sec_high(0);min_high5 <= time_min_high(2) and time_min_high(0);hour_high1 <= time_hour_high;sec_low9 <= time_sec_low(3) and time_sec_low(0);min_low9 <= time_min_low(3) and time_min_low(0);hour_low9 <= time_hour_low(3) and time_hour_low(0);hour_low1 <= time_hour_low(0);hour_low2 <= time_hour_low(1);sec_59 <= sec_high5 and sec_low9;min_sec_959 <= min_low9 and sec_59;min_sec_5959 <= min_high5 and min_sec_959;hour_min_sec_95959 <= hour_low9 and min_sec_5959;hour_min_sec_115959 <= hour_high1 and hour_low1 and min_sec_5959;hour_min_sec_125959 <= hour_high1 and hour_low2 and min_sec_5959;hour_12 <= hour_high1 and hour_low2;
모바일컴퓨터특강 30
Digital Watch - Time Controlprocess(clk, reset)begin if(reset='0') then time_ampm <= AM; elsif(clk'event and clk='1') then
if( (time_ampm_set_state='1' and inc_shot='1') or (normal_time_state='1' and one_sec='1' and hour_min_sec_115959='1'))
then time_ampm <= not(time_ampm);
end if;end if;
end process;
process(clk, reset)begin if(reset='0') then time_hour_high <= '1'; elsif(clk'event and clk='1') then
if( (time_hour_set_state='1' and inc_shot='1' and ( hour_low9='1' or hour_12='1') ) or(normal_time_state='1' and one_sec='1' and (hour_min_sec_95959='1' or
hour_min_sec_125959='1') ) ) then time_hour_high <= not(time_hour_high);
end if;end if;
end process;
11 시 59 분 59 초
9 시 59 분 59 초12 시 59 분 59 초
9 시 또는 12 시
모바일컴퓨터특강 31
Digital Watch - Time Control
process(clk, reset)begin if(reset='0') then time_hour_low <= "0010"; elsif(clk'event and clk='1') then
if( (time_hour_set_state='1' and inc_shot='1' and hour_low9='1') or(normal_time_state='1' and one_sec='1' and hour_min_sec_95959='1') )then
time_hour_low <= "0000"; elsif( (time_hour_set_state='1' and inc_shot='1' and hour_12='1') or
(normal_time_state='1' and one_sec='1' and hour_min_sec_125959='1') ) then time_hour_low <= "0001"; elsif( ( time_hour_set_state='1' and inc_shot='1') or
( normal_time_state='1' and one_sec='1' and min_sec_5959='1' ) )then time_hour_low <= time_hour_low+'1';
end if; end if;end process;
process(clk, reset)begin if(reset='0') then time_min_high <= "000"; elsif(clk'event and clk='1') then
if( (time_min_high_set_state='1' and inc_shot='1' and min_high5='1') or(normal_time_state='1' and one_sec='1' and min_sec_5959='1' )) then
time_min_high <= "000"; elsif( (time_min_high_set_state='1' and inc_shot='1') or
(normal_time_state='1' and one_sec='1' and min_sec_959='1' ) )then time_min_high <= time_min_high+'1';
end if;end if;
end process;
9 시 59 분 59 초
12 시 59 분 59 초
59 분 59 초
9 시
12 시
59 분 59 초
9 분 59 초
50 분
모바일컴퓨터특강 32
Digital Watch - Time Control
process(clk, reset)begin if(reset='0') then time_min_low <= "000"; elsif(clk'event and clk='1') then
if( (time_min_low_set_state='1' and inc_shot='1' and min_low9='1') or (normal_time_state='1' and one_sec='1' and min_sec_959='1' ) )then
time_min_low <= "0000"; elsif( (time_min_low_set_state='1' and inc_shot='1' ) or
(normal_time_state='1' and one_sec='1' and sec_59='1' ) )then time_min_low <= time_min_low+'1';
end if;end if;
end process;
process(clk, reset)begin if(reset='0') then time_sec_high <= "000"; elsif(clk'event and clk='1') then
if(normal_time_state='1' and one_sec='1' and sec_59='1' ) then time_sec_high <= "000";
elsif(normal_time_state='1' and one_sec='1' and sec_low9='1' ) then time_sec_high <= time_sec_high+'1';
end if;end if;
end process;
9 초
59 초
9 분 59 초
59 초
9 분
모바일컴퓨터특강 33
Digital Watch - Time Control
process(clk, reset)begin if(reset='0') then time_sec_low <= "0000"; elsif(clk'event and clk='1') then
if(normal_time_state='1' and one_sec='1' and sec_low9='1' ) then time_sec_low <= "0000";
elsif(normal_time_state='1' and one_sec='1' ) then time_sec_low <= time_sec_low+'1';
end if;end if;
end process;
process(clk,reset) -- time_cnt, buzzer_blink processingbegin
if(reset='0') then time_cnt <= "000000";
elsif(clk'event and clk='1') then if( time_min_low_set_state='1' and set_shot='1') then time_cnt <= “000000"; elsif( initial_state='1') then null; elsif(time_cnt = 49) then time_cnt<=“000000"; else time_cnt <= time_cnt+'1'; end if;
end if;end process;
9 초
1 초
0.5 초
모바일컴퓨터특강 34
Digital Watch - Time Control
process(clk,reset)begin
if(reset='0') then buzzer_blink <= '0';
elsif(clk'event and clk='1') then if( time_min_low_set_state='1' and set_shot='1') then buzzer_blink <= '0'; elsif(time_cnt = 49) then buzzer_blink <= not( buzzer_blink); end if;
end if;end process;
process(time_cnt,buzzer_blink)begin
if(time_cnt = 49 and buzzer_blink ='1' ) thenone_sec <='1';
elseone_sec <='0';
end if;end process;
end a;
1 초
0.5 초
모바일컴퓨터특강 35
Digital Watch – LedBlink (Flow)
led blinkcontrol mode
1
led_blink_cnt <=0led_blink <= not(led_blink)
led_blink_cnt=half_cnt
led_blink_cnt++
0
led_blink_cnt <= 0led_blink <= 1
state=initial_state
set_shot time_set_mode
set_shot or inc_shot
0
0
0
1
1
1
1
0
이 블럭의 목적은 키가 눌러졌을 때마다 FND 의 Display 를
동기화 시키는데 목적이 있는 것임 .1. 시스템의 초기상태 (Initial_State)
에서는 Set Key 만 센싱을 하게 되는데 , Set Key 가 눌러지면 눌러지는 시점에서부터 0.5 초간 FND의 값을 Display 를 ON 하고 다음 0.5 초간은 Display 를 OFF 한다 .
2. 시간을 고치는 시간수정모드(Time_Set_Mode) 에서는 Set Key 나 Inc Key 2 가지 입력 모두에 대해 센싱을 해서 어느 하나의 Key 라도 눌러지면 그 시점에 동기를 맞춰 Display On 시점을 다시 조정해서 0.5 초간은 Display ON 하며 다음 0.5 초간은 Display OFF 를 반복한다 .
3. Led_blink_cnt 는 30 초(Half_CnT) 를 세기위한 카운터임 .
4. Led_blink 가 1 이면 Display ON 이며 , 0 이면 Display OFF 의 상태임 .
이 블럭의 목적은 키가 눌러졌을 때마다 FND 의 Display 를
동기화 시키는데 목적이 있는 것임 .1. 시스템의 초기상태 (Initial_State)
에서는 Set Key 만 센싱을 하게 되는데 , Set Key 가 눌러지면 눌러지는 시점에서부터 0.5 초간 FND의 값을 Display 를 ON 하고 다음 0.5 초간은 Display 를 OFF 한다 .
2. 시간을 고치는 시간수정모드(Time_Set_Mode) 에서는 Set Key 나 Inc Key 2 가지 입력 모두에 대해 센싱을 해서 어느 하나의 Key 라도 눌러지면 그 시점에 동기를 맞춰 Display On 시점을 다시 조정해서 0.5 초간은 Display ON 하며 다음 0.5 초간은 Display OFF 를 반복한다 .
3. Led_blink_cnt 는 30 초(Half_CnT) 를 세기위한 카운터임 .
4. Led_blink 가 1 이면 Display ON 이며 , 0 이면 Display OFF 의 상태임 .
모바일컴퓨터특강 36
Digital Watch - LedBlink
-- purpose : led blink controlLIBRARY IEEE;USE IEEE.std_logic_1164.all;USE IEEE.std_logic_unsigned.all;
entity ledblink isport( clk : in std_logic; reset : in std_logic; set_shot : in std_logic; inc_shot : in std_logic;
initial_state : in std_logic;time_set_mode : in std_logic;
led_blink : buffer std_logic);end ledblink;
architecture a of ledblink issignal led_blink_cnt : std_logic_vector(5 downto 0);begin
모바일컴퓨터특강 37
Digital Watch - LedBlink
-- 0.5 sec led blink controlprocess(clk,reset)begin
if(reset='0') then led_blink_cnt <= "00000"; elsif(clk'event and clk='1') then if( initial_state='1' and set_shot='1') then led_blink_cnt <="00000"; elsif( time_set_mode='1' and (set_shot='1' or inc_shot='1'))
then led_blink_cnt <="00000"; else if(led_blink_cnt=49)then led_blink_cnt <="00000"; else led_blink_cnt <= led_blink_cnt+'1'; end if; end if; end if; -- end clk'event
end process;
Led_blink_Cnt 는 30 초씩 깜박임 조절을 위해 30 초(Half_CnT) 를 세기위한 카운터임 . 그러므로 Display를 새로이 하기위해서는 위의 두가 지 경우에 0 부터 다시 카운트 되어야 함 .
Led_blink_Cnt 는 30 초씩 깜박임 조절을 위해 30 초(Half_CnT) 를 세기위한 카운터임 . 그러므로 Display를 새로이 하기위해서는 위의 두가 지 경우에 0 부터 다시 카운트 되어야 함 .
초기상태 (Initial_State)에서는 Set SW 가 눌러졌을 경우에 Display 를 켜기부터 시작 ,
초기상태 (Initial_State)에서는 Set SW 가 눌러졌을 경우에 Display 를 켜기부터 시작 ,
시간수정모드(Time_Set_Mode)에서는 Set Sw 나 Inc Sw 가 눌러지는 경우에 Display 를 켜기부터 시작함 .
시간수정모드(Time_Set_Mode)에서는 Set Sw 나 Inc Sw 가 눌러지는 경우에 Display 를 켜기부터 시작함 .
모바일컴퓨터특강 38
Digital Watch - LedBlink
process(clk,reset)begin
if(reset='0') then led_blink <='0'; elsif(clk'event and clk='1') then if( initial_state='1' and set_shot='1') then led_blink <= '1'; elsif( time_set_mode='1' and (set_shot='1' or
inc_shot='1')) then led_blink <= '1'; elsif(led_blink_cnt=49)then led_blink <= not(led_blink); end if; end if;
end process;end a;
0.5 초가 지나면 Led_Blink 를 Toggle 해서 깜박임 조절함 .
0.5 초가 지나면 Led_Blink 를 Toggle 해서 깜박임 조절함 .
초기상태 (Initial_State)에서는 Set SW 가 눌러졌을 경우에 Display를 켜기 위해 Led_Blink=1 로 만듬 .
초기상태 (Initial_State)에서는 Set SW 가 눌러졌을 경우에 Display를 켜기 위해 Led_Blink=1 로 만듬 .
시간수정모드(Time_Set_Mode)에서는 Set Sw 나 Inc Sw 가 눌러지는 경우에 Display 를 켜기 위해 Led_Blink=1 로 만듬 .
시간수정모드(Time_Set_Mode)에서는 Set Sw 나 Inc Sw 가 눌러지는 경우에 Display 를 켜기 위해 Led_Blink=1 로 만듬 .
Led_blink 가 1 이면 Display ON 이며 , 0 이면 Display OFF 의 상태임 .
Led_blink 가 1 이면 Display ON 이며 , 0 이면 Display OFF 의 상태임 .
모바일컴퓨터특강 39
Digital Watch – LCD_IFlibrary ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all;use work.myLCD.all;
entity LCD_IF isport(
clk : in std_logic; -- 10KHz : 0.1msec = 100usecresetb : in std_logic;
-- LCD input : time information LCD_time_ampm_ap : in std_logic_vector(7 downto 0); LCD_time_ampm_m : in std_logic_vector(7 downto 0); LCD_time_hour_high : in std_logic_vector(7 downto 0); LCD_time_hour_low : in std_logic_vector(7 downto 0); LCD_time_min_high : in std_logic_vector(7 downto 0); LCD_time_min_low : in std_logic_vector(7 downto 0); LCD_time_sec_high : in std_logic_vector(7 downto 0); LCD_time_sec_low : in std_logic_vector(7 downto 0);
LCD_time_sec_colon : in std_logic_vector(7 downto 0);e : out std_logic;rw : out std_logic;rs : out std_logic;data : out std_logic_vector(7 downto 0)
);end LCD_IF;
architecture hb of LCD_IF issignal dsp_data : std_logic_vector(7 downto 0);signal clk2 : std_logic; -- 5KHz : 0.2msec = 200usecsignal Fclk2 : std_logic; -- 5KHz : 0.2msec = 200usecsignal LCD_mode : std_logic_vector(3 downto 0);signal cnt5 : std_logic_vector(4 downto 0); -- modulo 21 countersignal Func_Set_shot : std_logic; signal Normal_Mode : std_logic;signal Write_shot : std_logic;signal Line : std_logic_vector(1 downto 0); -- 2 bits counter
begin
입력클럭 clk=10
0us
입력클럭 clk=10
0us
ASCII Code 로
표시된 시간 정보
ASCII Code 로
표시된 시간 정보
LCD 의 제어를
위한 출력
LCD 의 제어를
위한 출력
모바일컴퓨터특강 40
Digital Watch – LCD_IFprocess(clk, resetb) -- modulo 2 counter gen.begin
if(resetb='0') thenclk2 <= '0';
elsif( clk='1' and clk'event )thenclk2 <= not clk2;
end if;end process;process(clk, resetb)begin
if(resetb='0') thenFclk2 <= '0';
elsif( clk='0' and clk'event )thenFclk2 <= clk2;
end if;end process;
process(clk2, resetb) -- modulo 21 counter gen.begin
if(resetb='0') thencnt5 <= "00000";
elsif( clk2='1' and clk2'event )thenif(cnt5 = "10100") then
cnt5 <= "00000";else
cnt5 <= cnt5 + "00001";end if;
end if;end process;process(clk2, resetb) -- Line Counter gen.begin
if(resetb='0') thenLine <= "00";
elsif( clk2='1' and clk2'event )thenif( cnt5 = "10100" ) then -- when cnt5=20 ?
Line <= Line + "01";else
Line <= Line;end if;
end if;end process;
2 분주회로Clk2 = Fclk2
= 200us
2 분주회로Clk2 = Fclk2
= 200us
Modulo 21 Counter
Modulo 21 Counter
Line = 21x200us =
41us
Line = 21x200us =
41us
모바일컴퓨터특강 41
Digital Watch – LCD_IFprocess(clk2, resetb) -- LCD Mode Allocationbegin
if(resetb='0') thenLCD_mode <= "0000";
elsif( clk2='1' and clk2'event )thenif( cnt5 = "10100" and Line = "11" ) then -- when 21*4*0.2msec = 16.8msec interval
if(LCD_mode = "1000") thenLCD_mode <= "1000";
elseLCD_mode <= LCD_mode + "0001";
end if;end if;
end if;end process;
process( LCD_mode )begin
if( LCD_mode = "1000") thenNormal_Mode <= '1';
elseNormal_Mode <= '0';
end if;end process;process( cnt5, Line, LCD_mode) -- Command Shot Pulse gen.begin
if( cnt5 = "00000" and Line = "00" and (LCD_mode < "1000") and not (LCD_mode="0000")) then -- 16.8msec intervalFunc_Set_shot <= '1';
elseFunc_Set_shot <= '0';
end if;end process;
16.8msec마다
LCD_mode증가하고 , 8
이면 LCD_mode 를
정지
16.8msec마다
LCD_mode증가하고 , 8
이면 LCD_mode 를
정지
LCD_mode=8 이면
Normal_Mode 로 함 .
LCD_mode=8 이면
Normal_Mode 로 함 .
LCD_mode 의 값이 1-7 인 범위일 떄 , 16.8 ms 마다
한번씩 Line=00미면서
cnt5=00000 인 구간에서
Func_Set_shot 를 1 로 만듬 .
LCD_mode 의 값이 1-7 인 범위일 떄 , 16.8 ms 마다
한번씩 Line=00미면서
cnt5=00000 인 구간에서
Func_Set_shot 를 1 로 만듬 .
모바일컴퓨터특강 42
Digital Watch – LCD_IF-- Write_Shot gen.process(Normal_Mode, cnt5)begin
if(cnt5 = "00000" and Normal_Mode ='1') thenWrite_Shot <= '1';
elseWrite_Shot <= '0';
end if;end process;
rw <= '0'; -- write only
rs <= not ( Func_Set_shot or Write_Shot );
e <= ( Func_Set_shot or Normal_Mode) and Fclk2;
process( LCD_mode )begin
case LCD_mode iswhen "0001" => data<="00111100"; -- Function Settingwhen "0010" => data<="00111100";when "0011" => data<="00111100";when "0100" => data<="00111100";when "0101" => data<="00000001"; -- Display Clearwhen "0110" => data<="00000110"; -- Entry Mode Settingwhen "0111" => data<="00001100"; -- Display On/Off settingwhen "1000" => data<= Dsp_Data;when others => data<="00000000";
end case;end process;
E, RS 발생RS 는 200us
동안만 0,
E 는 100usec동안만 1 로
만듬 .
E, RS 발생RS 는 200us
동안만 0,
E 는 100usec동안만 1 로
만듬 .
Write Only Mode.
Write Only Mode.
LCD 초기화과정
LCD 초기화과정
모바일컴퓨터특강 43
Digital Watch – LCD_IFprocess(clk)begin
if( Line = "00") then case cnt5 is
when "00000" =>dsp_data <="10000000"; -- DD Ram Addr = 00H
when "00100" =>dsp_data <= Ascii_D;
when "00101" =>dsp_data <= Ascii_I;
when "00110" =>dsp_data <= Ascii_G;
when "00111" =>dsp_data <= Ascii_I;
when "01000" =>dsp_data <= Ascii_T;
when "01001" =>dsp_data <=Ascii_A;
when "01010" =>dsp_data <=Ascii_L;
when "01100" =>dsp_data <=Ascii_W;
when "01101" =>dsp_data <=Ascii_A;
when "01110" =>dsp_data <=Ascii_T;
when "01111" =>dsp_data <=Ascii_C;
when "10000" =>dsp_data <=Ascii_H;
when others =>dsp_data <=Ascii_space;
end case;else
LCD 첫번째 라인 출력DIGITAL WATCH
LCD 첫번째 라인 출력DIGITAL WATCH
모바일컴퓨터특강 44
Digital Watch – LCD_IFcase cnt5 iswhen "00000" =>dsp_data <="11000000"; -- DD RAM addr = 40Hwhen "00100" =>dsp_data <= Ascii_T; --Twhen "00101" =>dsp_data <= Ascii_I; --Iwhen "00110" =>dsp_data <= Ascii_M; --Mwhen "00111" =>dsp_data <= Ascii_E; --Ewhen "01000" =>dsp_data <= Ascii_colon; --: when "01001" =>dsp_data <= LCD_time_ampm_ap;when "01010" =>dsp_data <= LCD_time_ampm_m;when "01100" =>dsp_data <= LCD_time_hour_high;when "01101" =>dsp_data <= LCD_time_hour_low ;when "01110" =>dsp_data <= Ascii_colon; --: when "01111" =>dsp_data <= LCD_time_min_high ;when "10000" =>dsp_data <= LCD_time_min_low ;when "10001" =>dsp_data <= LCD_time_sec_colon ;when "10010" =>dsp_data <= LCD_time_sec_high ;when "10011" =>dsp_data <= LCD_time_sec_low ;when others =>dsp_data <= Ascii_space;end case;
end if;end process;
end hb;
LCD 두 번째 라인 출력 ( 예 )
TIME:AM 12:07:25
LCD 두 번째 라인 출력 ( 예 )
TIME:AM 12:07:25
모바일컴퓨터특강 45
Digital Watch– LCD_IF Timing
16.8ms 16.8ms 16.8ms 16.8ms 16.8ms16.8ms 16.8ms16.8ms
16.8msec마다 rs, e 를
하나씩 발생해서
Function Set.
16.8msec마다 rs, e 를
하나씩 발생해서
Function Set.
7 번의 명령어를 세팅 후에 LCD 에
문자를 써 넣는다 .
7 번의 명령어를 세팅 후에 LCD 에
문자를 써 넣는다 .
Function Setting
Function Setting
Function Setting
Function Setting
Display Clear
Entry Mode Setting
DisplayOn/Off setting DD Ram Addr = 00H
모바일컴퓨터특강 46
Digital Watch – LCD_IF Timing
Cnt5 는 Modulo 21 Counter Line 은 Cnt5 가 20 일 때만 증가
모바일컴퓨터특강 47
Digital Watch – LCD_IF Timing
Line 은 cnt5=20 일 때만 증가하며 Line=3 이 되면 0 으로 증가
LCD_Mode 는 Line=3 이며 , cnt5=20 일 때만 증가 확대는
다음 쪽확대는 다음 쪽
모바일컴퓨터특강 48
Digital Watch – LCD_IF Timing
LCD_Mode 는 Line=3 이며 , cnt5=20 일 때만 증가4x21=84(clkx2)
84x0.2msec=16.8.msec
전원 켜진 후16.8msec지나서 rs, e를 하나 발생 .
전원 켜진 후16.8msec지나서 rs, e를 하나 발생 .
0.5 clk = 0.5 x
0.1msec=0.05msec=50us
ec
0.5 clk = 0.5 x
0.1msec=0.05msec=50us
ec
50usec 50usec
100usec
LCD 의 Setup Time, Hold
Time 을 만족함 .
LCD 의 Setup Time, Hold
Time 을 만족함 .
모바일컴퓨터특강 49
Digital Watch – LCD_IF Timing
첫번째 라인에 해당되는 문자20 개 써 넣기 .
첫번째 라인에 해당되는 문자20 개 써 넣기 .
DD Ram Addr = 00H
모바일컴퓨터특강 50
Digital Watch – LCD_IF Timing
1 번째의 명령어 : 00111100
Function Setting
1 번째의 명령어 : 00111100
Function Setting
모바일컴퓨터특강 51
Digital Watch – LCD_IF Timing
2 번째의 명령어 : 00111100
Function Setting
2 번째의 명령어 : 00111100
Function Setting
모바일컴퓨터특강 52
Digital Watch – LCD_IF Timing
3 번째의 명령어 : 00111100
Function Setting
3 번째의 명령어 : 00111100
Function Setting
모바일컴퓨터특강 53
Digital Watch – LCD_IF Timing
4 번째의 명령어 : 00111100
Function Setting
4 번째의 명령어 : 00111100
Function Setting
모바일컴퓨터특강 54
Digital Watch – LCD_IF Timing
5 번째의 명령어 : 00000001
Display Clear
5 번째의 명령어 : 00000001
Display Clear
모바일컴퓨터특강 55
Digital Watch – LCD_IF Timing
6 번째의 명령어 : 0000110
Entry Mode Setting
6 번째의 명령어 : 0000110
Entry Mode Setting
모바일컴퓨터특강 56
Digital Watch – LCD_IF Timing
7 번째의 명령어 : 00001100
Display On/Off setting
7 번째의 명령어 : 00001100
Display On/Off setting
모바일컴퓨터특강 57
Digital Watch – LCD_IF Timing
8 번째의 명령어 : 10000000
DD Ram Addr = 00H
8 번째의 명령어 : 10000000
DD Ram Addr = 00H
첫째 라인의 1-3 번째 lcd 의 문자 : SPACE
첫째 라인의 1-3 번째 lcd 의 문자 : SPACE
첫째 라인의 4번째 lcd의 문자 :
D
첫째 라인의 4번째 lcd의 문자 :
D
첫째 라인의 4번 재 lcd의 문자 :
I
첫째 라인의 4번 재 lcd의 문자 :
I
모바일컴퓨터특강 58
Digital Watch – ToLCDBlink
Library IEEE;use ieee.std_logic_1164.all;use work.myLCD.all;entity ToLCDBlink isport(
initial_state : in std_logic;time_ampm_set_state : in std_logic;time_hour_set_state : in std_logic;time_min_high_set_state : in std_logic;time_min_low_set_state : in std_logic;normal_time_state : in std_logic;
led_blink : in std_logic;
-- time clock time_ampm : in std_logic; time_hour_high : in std_logic; time_hour_low : in std_logic_vector(3 downto 0); time_min_high : in std_logic_vector(2 downto 0); time_min_low : in std_logic_vector(3 downto 0); time_sec_high : in std_logic_vector(2 downto 0); time_sec_low : in std_logic_vector(3 downto 0);
-- LCD input : time information LCD_time_ampm_ap : out std_logic_vector(7 downto 0); LCD_time_ampm_m : out std_logic_vector(7 downto 0); LCD_time_hour_high : out std_logic_vector(7 downto 0); LCD_time_hour_low : out std_logic_vector(7 downto 0); LCD_time_min_high : out std_logic_vector(7 downto 0); LCD_time_min_low : out std_logic_vector(7 downto 0); LCD_time_sec_high : out std_logic_vector(7 downto 0); LCD_time_sec_low : out std_logic_vector(7 downto 0);
LCD_time_sec_colon : out std_logic_vector(7 downto 0));end ToLCDBlink;
BCD값
BCD값
ASCII 코드값
ASCII 코드값
Led_blink=0 이면 화면에
표시를 끔
Led_blink=0 이면 화면에
표시를 끔
상태(State)
상태(State)
모바일컴퓨터특강 59
Digital Watch – ToLCDBlink
Architecture a of ToLCDBlink isbeginprocess( initial_state, time_ampm_set_state,
time_hour_set_state, time_min_high_set_state, time_min_low_set_state, normal_time_state, led_blink)
beginif( (initial_state or time_ampm_set_state
or time_hour_set_state or time_min_high_set_state or time_min_low_set_state)='1' ) then
LCD_time_sec_colon <= Ascii_space;else
LCD_time_sec_colon <= Ascii_colon;end if;if( (initial_state='1' or time_ampm_set_state='1' ) and led_blink='0') then
LCD_time_ampm_ap <= Ascii_space; LCD_time_ampm_m <= Ascii_space;
elseif(time_ampm='0') then
LCD_time_ampm_ap <= Ascii_A; --Aelse
LCD_time_ampm_ap <= Ascii_P; --Pend if;LCD_time_ampm_m <= Ascii_M;
end if;if( (initial_state='1' or time_hour_set_state='1' ) and led_blink='0') then
LCD_time_hour_high <= Ascii_space; LCD_time_hour_low <= Ascii_space;
elseif( time_hour_high ='1') then
LCD_time_hour_high <= Ascii_1;else
LCD_time_hour_high <= Ascii_space; end if;LCD_time_hour_low <= HextoAscii(time_hour_low);
end if;
AM/PM 의 처리AM/PM 의 처리
시 (Hour) 의 처리시 (Hour) 의 처리
Led_blink=0이면 화면에
표시를 끔
Led_blink=0이면 화면에
표시를 끔
모바일컴퓨터특강 60
Digital Watch – ToLCDBlink
if( (initial_state='1' or time_min_high_set_state='1' ) and led_blink='0') then
LCD_time_min_high <= Ascii_space; else
LCD_time_min_high <= HextoAscii('0' & time_min_high);end if;
if( (initial_state='1' or time_min_low_set_state='1' ) and led_blink='0') then
LCD_time_min_low <= Ascii_space; else
LCD_time_min_low <= HextoAscii(time_min_low);end if;
if( normal_time_state='1' ) thenLCD_time_sec_high <= HextoAscii(time_sec_high);LCD_time_sec_low <= HextoAscii(time_sec_low);
elseLCD_time_sec_high <= Ascii_space; LCD_time_sec_low <= Ascii_space;
end if;
end process;
end a;
분 10 의 자리 (Min high) 의 처리
분 10 의 자리 (Min high) 의 처리
분 1 의 자리 (Min Low) 의 처리
분 1 의 자리 (Min Low) 의 처리
초 (sec) 의 처리초 (sec) 의 처리
모바일컴퓨터특강 61
Digital Watch– myLCD(Package)-- LCD Library Header File : myLCD.vhd
library ieee; use ieee.std_logic_1164.all;
package myLCD isCONSTANT Ascii_space : std_logic_vector(7 downto 0) := "00100000"; -- 20CONSTANT Ascii_colon : std_logic_vector(7 downto 0) := "00111010"; -- 3aCONSTANT Ascii_semicolon : std_logic_vector(7 downto 0) := "00111011"; -- 3bCONSTANT Ascii_0 : std_logic_vector(7 downto 0) := "00110000"; -- 30CONSTANT Ascii_1 : std_logic_vector(7 downto 0) := "00110001";CONSTANT Ascii_2 : std_logic_vector(7 downto 0) := "00110010";CONSTANT Ascii_3 : std_logic_vector(7 downto 0) := "00110011";CONSTANT Ascii_4 : std_logic_vector(7 downto 0) := "00110100";CONSTANT Ascii_5 : std_logic_vector(7 downto 0) := "00110101";CONSTANT Ascii_6 : std_logic_vector(7 downto 0) := "00110110";CONSTANT Ascii_7 : std_logic_vector(7 downto 0) := "00110111";CONSTANT Ascii_8 : std_logic_vector(7 downto 0) := "00111000";CONSTANT Ascii_9 : std_logic_vector(7 downto 0) := "00111001"; -- 39CONSTANT Ascii_A : std_logic_vector(7 downto 0) := "01000001"; -- 41CONSTANT Ascii_B : std_logic_vector(7 downto 0) := "01000010";CONSTANT Ascii_C : std_logic_vector(7 downto 0) := "01000011";CONSTANT Ascii_D : std_logic_vector(7 downto 0) := "01000100";CONSTANT Ascii_E : std_logic_vector(7 downto 0) := "01000101";CONSTANT Ascii_F : std_logic_vector(7 downto 0) := "01000110";CONSTANT Ascii_G : std_logic_vector(7 downto 0) := "01000111";CONSTANT Ascii_H : std_logic_vector(7 downto 0) := "01001000";CONSTANT Ascii_I : std_logic_vector(7 downto 0) := "01001001";CONSTANT Ascii_J : std_logic_vector(7 downto 0) := "01001010";CONSTANT Ascii_K : std_logic_vector(7 downto 0) := "01001011";CONSTANT Ascii_L : std_logic_vector(7 downto 0) := "01001100";CONSTANT Ascii_M : std_logic_vector(7 downto 0) := "01001101";CONSTANT Ascii_N : std_logic_vector(7 downto 0) := "01001110";CONSTANT Ascii_O : std_logic_vector(7 downto 0) := "01001111";CONSTANT Ascii_P : std_logic_vector(7 downto 0) := "01010000";CONSTANT Ascii_Q : std_logic_vector(7 downto 0) := "01010001";CONSTANT Ascii_R : std_logic_vector(7 downto 0) := "01010010";CONSTANT Ascii_S : std_logic_vector(7 downto 0) := "01010011";CONSTANT Ascii_T : std_logic_vector(7 downto 0) := "01010100";CONSTANT Ascii_U : std_logic_vector(7 downto 0) := "01010101";CONSTANT Ascii_V : std_logic_vector(7 downto 0) := "01010110";CONSTANT Ascii_W : std_logic_vector(7 downto 0) := "01010111";CONSTANT Ascii_X : std_logic_vector(7 downto 0) := "01011000";CONSTANT Ascii_Y : std_logic_vector(7 downto 0) := "01011001";CONSTANT Ascii_Z : std_logic_vector(7 downto 0) := "01011010"; -- 5aCONSTANT Ascii_small_a : std_logic_vector(7 downto 0) := "01100001"; -- 61CONSTANT Ascii_small_b : std_logic_vector(7 downto 0) := "01100010";CONSTANT Ascii_small_c : std_logic_vector(7 downto 0) := "01100011";CONSTANT Ascii_small_d : std_logic_vector(7 downto 0) := "01100100";
ASCII Code 의 상수선언ASCII Code 의 상수선언
모바일컴퓨터특강 62
Digital Watch – myLCD(Package)CONSTANT Ascii_small_e : std_logic_vector(7 downto 0) := "01100101";
CONSTANT Ascii_small_f : std_logic_vector(7 downto 0) := "01100110";CONSTANT Ascii_small_g : std_logic_vector(7 downto 0) := "01100111";CONSTANT Ascii_small_h : std_logic_vector(7 downto 0) := "01101000";CONSTANT Ascii_small_i : std_logic_vector(7 downto 0) := "01101001";CONSTANT Ascii_small_j : std_logic_vector(7 downto 0) := "01101010";CONSTANT Ascii_small_k : std_logic_vector(7 downto 0) := "01101011";CONSTANT Ascii_small_l : std_logic_vector(7 downto 0) := "01101100";CONSTANT Ascii_small_m : std_logic_vector(7 downto 0) := "01101101";CONSTANT Ascii_small_n : std_logic_vector(7 downto 0) := "01101110";CONSTANT Ascii_small_o : std_logic_vector(7 downto 0) := "01101111";CONSTANT Ascii_small_p : std_logic_vector(7 downto 0) := "01110000";CONSTANT Ascii_small_q : std_logic_vector(7 downto 0) := "01110001";CONSTANT Ascii_small_r : std_logic_vector(7 downto 0) := "01110010";CONSTANT Ascii_small_s : std_logic_vector(7 downto 0) := "01110011";CONSTANT Ascii_small_t : std_logic_vector(7 downto 0) := "01110100";CONSTANT Ascii_small_u : std_logic_vector(7 downto 0) := "01110101";CONSTANT Ascii_small_v : std_logic_vector(7 downto 0) := "01110110";CONSTANT Ascii_small_w : std_logic_vector(7 downto 0) := "01110111";CONSTANT Ascii_small_x : std_logic_vector(7 downto 0) := "01111000";CONSTANT Ascii_small_y : std_logic_vector(7 downto 0) := "01111001";CONSTANT Ascii_small_z : std_logic_vector(7 downto 0) := "01111010"; -- 7a
-- Hex to Ascii decoderfunction HexToAscii(hex_in : std_logic_vector(3 downto 0)) return std_logic_vector ;end myLCD;
package body myLCD is-- Hex to Ascii decoderfunction HexToAscii(hex_in : std_logic_vector(3 downto 0)) return std_logic_vector isvariable Ascii_out : std_logic_vector(7 downto 0);begin case hex_in is
when "0000" => Ascii_out := Ascii_0;when "0001" => Ascii_out := Ascii_1;when "0010" => Ascii_out := Ascii_2;when "0011" => Ascii_out := Ascii_3;when "0100" => Ascii_out := Ascii_4;when "0101" => Ascii_out := Ascii_5;when "0110" => Ascii_out := Ascii_6;when "0111" => Ascii_out := Ascii_7;when "1000" => Ascii_out := Ascii_8;when "1001" => Ascii_out := Ascii_9;when others => Ascii_out := Ascii_space;
end case; return (Ascii_out);end HexToAscii;end myLCD;
ASCII Code 의 상수선언ASCII Code 의 상수선언
BCD to ASCII Code 변환 함수선언
BCD to ASCII Code 변환 함수선언