Programming and simulation.
1. Taxi meter VHDL program
-- File name: taxi.hd
-- Function: Taxi meter
library IEEE;
use IEEE.STD_LOG IC _1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity taxi is
port ( clk_240 :in std_logic; --Clock start with a frequency of 240Hz
:in std_logic; --Pricing enable signal
stop:in std_logic; --Waiting signal
fin:in std_logic; --Kilometer pulse signal
cha3,cha2,cha1,cha0:out std_logic_vector(3 downto 0); --Fee data
km1,km0:out std_logic_vector(3 downto 0); --Kilometer data
min1,min0: out std_logic_vector(3 downto 0)); --Waiting time
end taxi;
architecture behav of taxi is
signal f_15,f_16,f_1:std_logic; --Frequency signal of 15Hz, 16Hz, 1Hz
signal q_15:integer range 0 to 15; --Frequency divider
signal q_16:integer range 0 to 14; --Frequency divider signal q_1:integer range 0 to 239; --Frequency divider signal w:integer range 0 to 59; --Second counter signal c3,c2,c1,c0:std_logic_vector(3 downto 0); --Toll counter signal k1,k0:std_logic_vector(3 downto 0); --Kilometer counter signal m1:std_logic_vector(2 downto 0); --Tens counter signal m0:std_logic_vector(3 downto 0); --Units counter signal en1,en0,f:std_logic; -- Enable signal begin fei PIN : process (clk_240,start) begin if clk_240'event and clk_240='1' then if start='0' then q_15<=0;q_16<=0;f_15<='0';f_16<='0';f_1<='0';f<='0'; else if q_15=15 then q_15<=0;f_15<='1'; --This statement gets a signal with a frequency of 15Hzelse q_15<=q_15+1;f_15<='0'; end if; if q_16=14 then q_16<=0;f_16<='1'; --This statement gets a signal with a frequency of 16Hzelse q_16<=q_16+1;f_16<='0'; end if; if q_1=239 then q_1<=0;f_1<='1'; --This statement gets a signal with a frequency of 1Hz else q_1<=q_1+1;f_1<='0'; end if; if en1='1' then f<=f_15; --This statement gets the billing pulse f elsif en0='1' then f<=f_16; else f<='0'; end if; end if; end if; end process; process(f_1) begin if f_1'event and f_1='1' then if start='0' then w<=0;en1<='0';en0<='0';m1<="000";m0<="0000";k1<="0000";k0<="0000"; elsif stop='1' then
if w=59 then w<=0; --This statement completes the waiting timingif
m0="1001" then m0<="0000"; --This statement completes the minute countingif
m1<="101" then m1<="000";
else m1<=m1+1;
end if;
else m0<=m0+1;
end if;
if m1&m0>"0000001"then en1<='1'; --This statement gets the en1 enable signalelse
en1<='0';
end if;
else w<=w+1;en1<='0';
end if;
elsif fin='1' then
if k0="1001" then k0<="0000"; --This statement completes the kilometer pulse countingif
k1="1001" then k1<="0000";
else k1<=k1+1;
end if;
else k0<=k0+1;
end if;
if k1&k0>"00000010" then en0<='1'; --This statement gets the en0 enable signal
else en0<='0';
end if;
else en1<='0';en0<='0';
end if;
cha3<=c3;cha2<=c2;cha1<=c1;cha0<=c0; --Cost data output
km1<=k1;km0<=k0;min1<='0'&m1;min0<=m0; --Kilometer data, minute data output
end if;
end process;
process(f,start)
begin
if start='0' then c3<="0000";c2<="0001";c1<="0000";c0<="0000";
elsif f'event and f='1' then
if c0="1001" then c0<="0000"; --This statement completes the cost counting
if c1="1001" then c1<="0000";
if c2="1001" then c2<="0000";
if c3<="1001" then c3<="0000";
else c3<=c3+1;
end if;
else c2<=c2+1;
end if;
else c1<=c1+1;
end if;
else c0<=c0+1;
end if;
end if;
end process;
end behav;
2. Program simulation diagram
Note: 1. The relationship between seconds and minutes in the simulation diagram is ternary, that is, when w is 2, it returns to 0;
2. The taxi traveled a total of 5 kilometers, the cumulative waiting time was 4 minutes, and the total fare was 16.2 yuan.
Figure 8.22.3 Taxi meter program simulation full picture
Previous article:Microcontroller C language in application design
Next article:Design of Interface Program between SED1335 and 51 Single Chip Microcomputer
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- [Project source code] CYUSB3014 chip cannot download firmware using EEPROM
- Looking forward to Huawei's operating system!
- Test parameters of 1630MHz125 amplifier
- Why can't the segment code LCD screen be lit up when driving with STML152?
- Disassembling Nokia Bluetooth Headset BH501 from over 10 years ago
- Analysis of the types of pads and design standards in PCB design
- The pitfalls encountered when playing with TMS320F28379D
- Add RTT log output to common projects. Simple configuration. It is very easy to use.
- The control motor is found to have insufficient stroke. Please provide a solution.
- [Flower carving DIY] Interesting and fun music visualization series project (27) - Magnetic stirring LED water rotating lamp