标题: 房间电器综合控制系统 [打印本页] 作者: chang123456 时间: 2017-5-1 17:15 标题: 房间电器综合控制系统 房间电器综合控制系统
Control system of the electrisic in the room
摘 要
本设计的目的是寻找一种方法来实现房间内多种电器的综合控制,采用了单片机与红外遥控相结合的方式,制作出一种房间电器综合控制系统。系统的核心由AT89S52单片机和红外收发装置构成,整个系统包括发射部分和接收部分。发射部分以AT89S52单片机为中心控制芯片,外围扩展了矩阵键盘,红外发射电路以及电源电路;接收部分则以AT89S52单片机为核心,外围扩展了红外接收电路,按键显示电路,电源电路以及与按键相应的继电器控制家用电器电路。红外信号的发射采用脉冲个数编码的方式,根据不同的按键设定不同的编码,通过软件实现解码,从而控制相应电器的开和关。通过硬件和软件相结合的方式,此设计实现了手持遥控器,按下一个按键,相应的电器接通电源开始工作,并显示按键号码,再按一下,该电器切断电源停止工作。此设计具有操作码个数可随意设定,编程灵活多样等优点。
关键词:单片机;红外;编码解码
ABSTRACT
The aid of this ariticle is to search a way to
附录1 程序
A/D转换控制程序
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity ADKONGZHI is
port(d:in std_logic_vector(7 downto 0);
rst:in std_logic;
clk:in std_logic;
eoc:in std_logic;
ale:out std_logic;
start:out std_logic;
oe:out std_logic;
adda:out std_logic;
bcdout:out std_logic_vector(11 downto 0)
);
end entity SDKONGZHI;
architecture art of ADKONGZHI is
type states is (st0,st1,st2,st3,st4,st5,st6);
signal current_state,next_state:states;
signal regl:std_logic_vector(7 downto 0);
signal lock0,lock1:std_logic;
signal value:std_logic_vector(11 downto 0);
signal cen:std_logic;
signal ale0:std_logic;
signal start0:std_logic;
signal oe0:std_lognal;
begin
statesystem:block is
begin
adda<=’1’;
process(current_state,eoc)
case current_state is
when st0 =>ale0<=’0’;start0<=’0’;oe0<=’0’;
lock0<=’0’;next_state<=st1;cen<=’0’;
when st1 =>ale0<=’1’;start0<=’0’;oe0<=’0’;
lock0<=’0’;next_state<=st2;cen<=’0’;
when st2 =>ale0<=’0’;start0<=’1’;oe0<=’0’;
lock0<=’0’;next_state<=st3;cen<=’0’;
when st3 =>ale0<=’0’;start0<=’0’;oe0<=’0’;
lock0<=’0’;cen<=’0’;
if eoc=’1’ then next_state<=st3;
else next_state<=st4;
end if;
when st4 =>ale0<=’0’;start0<=’0’;oe0<=’0’;
lock0<=’0’; cen<=’0’;
if eoc=’0’ then next_state<=st4;
else next_state<=st5;
end if;
when st5=>ale0<=’0’;start0<=’0’;oe0<=’1’;
lock0<=’1’;next_state<=st6;cen<=’1’;
when st6=>ale0<=’0’;start0<=’0’;oe0<=’1’;
lock0<=’1’;next_state<=st0;cen<=’0’;
when others =>ale0<=’0’;start0<=’0’;oe0<=’1’;
lock0<=’0’;next_state<=st0;cen<=’0’;
end case;
end procsee;
process(rst,clk)
begin
if rst=’1’ then current_state<=st0;
elsif rising_edge(clk) then current_state<=next_state;
end if;
end process;
process(clk)
begin
if rising_edge(clk) then ale<=ale0;start<=start0;oe<=oe0;lock1<=lock1;
end if;
end process;
process(lock1)
begin
if rising_edge(lock) then regl<=d;
end if;
end process;
end block statesystem;
conversion:block is
signal v:std_logic_vector(7 downto 0);
signal hb,lb:std_logic_vector(11 downto 0);
signal c30,c74,c118:std_logic;
signal tempa,tempb,tempc:std_logic_vector(4 downto 0);
begin
process(regl)
begin
v<=regl;
case v(7 downto 4) is
when “1111” =>hb<=”010010000000”;
when “1110” =>hb<=”010001001000”;
when “1101” =>hb<=”010000010110”;
when “1100” =>hb<=”001110000100”;
when “1011” =>hb<=”001101010010”;
when “1010” =>hb<=”001100100000”;
when “1001” =>hb<=”001010001000”;
when “1000” =>hb<=”001001010110”;
when “0111” =>hb<=”001000100100”;
when “0110” =>hb<=”000110010010”;
when “0101” =>hb<=”000101100000”;
when “0100” =>hb<=”001001010000”;
when “0011” =>hb<=”000010010110”;
when “0010” =>hb<=”000001100010”;
when “0001” =>hb<=”000000110010”;
when others =>hb<=”000000000000”;
end case;
case v(3 downto 0) is
when “1111” =>lb<=”000000110000”;
when “1110” =>lb<=”000000101000”;
when “1101” =>lb<=”000000100110”;
when “1100” =>lb<=”000000100100”;
when “1011” =>lb<=”000000100010”;
when “1010” =>lb<=”000000100000”;
when “1001” =>lb<=”000000011000”;
when “1000” =>lb<=”000000010110”;
when “0111” =>lb<=”000000010100”;
when “0110” =>lb<=”000000010010”;
when “0101” =>lb<=”000000010000”;
when “0100” =>lb<=”000000001000”;
when “0011” =>lb<=”000000000110”;
when “0010” =>lb<=”000000000100”;
when “0001” =>lb<=”000000000010”;
when others =>lb<=”000000000000”;
end case;
end process;
process(hb,lb cen)
variable temp1,temp2,temp3:std_logic_vector(3 downto 0);
begin
if rising_edge(cen) then
temp1:=hb(3 downto 0)+lb(3 downto 0);
if temp1>”1001” then
temp1:=temp1+”0110”;
temp2:=hb(7 downto 4)+lb(7 downto 4)+’1’;
if temp2>”1001” then
temp2:=temp2+”0110”;
temp3:=hb(11 downto 8)+lb(11 downto 8)+’1’;
if temp3>”1001 then
temp3:=temp3+”0110”;
end if;
else temp3:=hb(11 downto 8)+lb(11 downto 8);
if temp3>”1001” then
temp3:=temp3+”0110”;
end if;
end if;
else
temp2 :=hb(7 downto 4)+lb(7 downto 4);
if temp2>”1001” then
temp2:=temp2+”0110”;
temp3:=hb(11 downto 8)+lb(11 downto 8)+’1’;
if temp3>”1001” then
temp3:=temp3+”0110”;
end if;
else
temp3:=hb(11 downto 8)+lb(11 downto 8);
if temp3>”1001” then
temp3:=temp3+”0110”;
end if;
end if;
end if;
end if;
value<=temp3&temp2&temp1;
end process;
bcdout<=value;
end block conversion;
end architecture;
附录2 EP1K100QC208-3简单介绍说明
附录3 系统整体电路图
附录4 系统PCB板图
英文资料及中文翻译
Digital Communication System
For modern people, if you do not know “Digital Communication” or “Digital Signal”, it is seem to be outdated, even would be laughed as “a ignorant men” . well then ,what is the “Digital Communication” and what is the “Digital Signal” ? This text is to do an generalize in the way of brief and plain.
1、Why Digital?
Why are communication system,military and commercial alike,“going digital”?The primary advantage is the ease with which digital signals,compared with analog signals,are regenerated. Figure 1 illustrates an ideal binary digital pulse propagating along a transmission line. The shape of the waveform is affected by two basic mechanisms: (1) as all transmission lines and circuits have some nonideal frequence transfer function,there is a distorting effect on the ideal and pulse; and (2) unwanted electrical noise or other interference further distorts the pulse waveform. Both of these mechanisms cause the pulse shape to degrade as a function of line lenge,as shown in Figure 1. During the time that the transmitted pulse can still be reliably identified before it is degraded to an ambiguous state,the pulse is amplified by a digital amplifier that recovers its original ideal shape. The pulse is thus “rebor” or regenerated. Circuits that perform this function at regular intervals along a transmission system are called regenerative repeaters.
Distance 1 Distance 2 Dance 3 stance 4 Distance 5
Original Some signal Degraded Signal is badly Amplification
dstortiuon dstortiuon dstortiuon degraded regenerate pulse
Propagation distance
Figure 1 Pulse degradation and regeneration
Digital circuit are less subject to distortion and interfernce than analog circuit . Becanse binary circuits opoerate in one of two states fully on fully of —to be meaningful,a disturbance must be large enough to change the circuit ooperating point from one state to the other. Such two-state operation facilitates signal regeneration and thus prevents noise and other disturbances from accumulating in transmission. Analog signals,however,are not two-state signals; they can take an infinite variety of shapes. With analog circuits,even a small disturbance can render the reproduced waveform unacceptably distorted. Once the analog signal is distorted,the distortion cannot be removed by amplification. Because accumulated noise is irrevocably bound to analog signals,they cannot be perfectly regenerated. With digital techniques,extremely low error rates produres high signal fidelity are possible through error detection and correction but similar procedures are not available with analog.
There are other important advantages to digital communications. Digital circuit are more reliable and can be produced at a lower cost than analog circuit . Also, digital hardwave lends itself to more flexble implementation than analog hardwave (e.g., microprocessor, digital switching, and large-scale integrated (LSI) circuit). The combing of digital signals using time-division multiplexing (TDM) is simpler than the combing of analog signals using frequcency-division multiplexing (FDM). Different types of digital signals (data, telegraph, telephone, television) can be treated as identical signals in transmission and switching ---a bit is a bit. Also, for convenient switching, digital messages can be handled in autonomous groups called packets. Digital techniques lend themselves naturally to signal processing functions that project against interferene and jamming,or that provide encryption and privacy. Also much data communication is from computer to computer, or from digital instruments or terminal to computer. Such digital terminations are naturally best served by digital communication links.
What are the costs associated with the beneficial attributes of digital cimmunication system? Digital system tend to be very signal-processing intensive compared with analog. Also, digital system need to allocate a significant share of their resources to the task of synchroniztion at various levels . With analog system , on the other hand , synchroniztion often is accomplished more easily. One disadvantage of a digital communication system is non-graceful degradation. When the signal-to-noise ratio drops below a certain threshold, the quality of service can change suddenly from very poor. In cintrast, most communication aystem degrade more gracefully.
2、Typical Blook Diagram and Transformations
The function block diagram shown in Figure 2 illustrates the signal flow and the signal-processing steps through a typical digital communication system (DCS). This figure can serve as a kind of road map, guiding the reader through the chapter. The upper blocks --- format, source encode, encrypt, channel encode, multiplex ,pulse modulate, bandpass modulate, frequency spread, and multiple access-denote signal transformations from the source to the transmitter. The lower block denote signal transformations from the receiver to the sink, essentially reversing the signal processing steps performed by the upper blocks. The modulate and demodulate/detect blocks together are called a modern. The term “modern” often encompasses several of the signal processing steps shown in Figure 2 ; When this is the case, the modern can be though of as the “brain” of the system. The transmitter and receiver can be though of as the “muscles” of the system. For wireless applications, the transmitter and consists of a frequency up-conversion stage to a radio frequency (RF), a high-power amplifier(LNA). Frequency down-conversion is performed in the fornt end of the receiver and/or the demodulator.
Figure 2 illustrates a kind of reciprocity between the block in the upper transmitter part of the figure and those in the lower receiver part. The signal processing steps that take place in the transmitter are, for the most part, reversed in the reveiver. In Figure 2 , the input information source is converted to binary digits (bis); the bits are then grouped to from digital message or message.
Each such symbol (mi,where i=1,2,3,…,M) can be regarded as a memerber of finite alphabet set containing M members. Thus, for M=2, the message symbol mi is binary (meaning that it constitutes just a signal bit). Even though binary symbol fall within the general definition of M-ary, nevertheless the name M-ary is usually applied to those cases where M>2 ; hence, such symbol are each made up of a sequence of two or more bits. (Compare such a finite alphabet in a DCS with an analog system, where the message waveform is typically a member of an infinite set of possible waveform ). For system that use channel coding (error correction coding), a sequence of message symbol is denoted ui. Because a message symbol or a channel symbol can consist of a single bit or a group of bits, a sequence of such symbol is also described as a bit stream, as shown in Figure 2.
Consider the key signal processing block shown in Figure 2 , Only formatting, modulation, demodulation/detection, and synchronization are essential for a DCS. Formatting, transform the source information into bits, thus assuring compatibility between the information and the signal processing within the DCS. From this point in the figure up to the pulse-modulation block, the information remains in the form of a bit stream. Modulation is the process by which message symbols or channel symbols (when channel coding is used) are converted to waveforms that are compatible with the requirements imposed by the transmission channel . Pulse modulation is an essential step because each symbol to be transmitted must first be transformed from a binary representation (voltage levels representing binary ones and zeros) to a baseband waveform. The term baseband refers to a signal whose spectrum extends from (or near) dc up to some finite value, usually less than a few megahertz. The pulse-modulation block usually includes filtering
for minimizing the transmission bandwidth. When pulse modulation is applied to binary sym-
si(t)
From other
sources
Digital
input mi ui gi(t)
m(t) u(t)
Z(t)
To other
destination
r(t)
Figure 2 A typical digital communication system
bols, the resulting binary waveform is called a pulse-code modulation (PCM) waveform. There are several types of PCM waveform. In telephone applications, these waveforms are often called line codes. When pulse modulation is applied to nonbinary symbols, the resulting waveform is called an M- ary pulse modulation wave form. There are several types of such waveforms,where the one called pulse-amplitude modulation (PAM) is emphasized. After pulse modulation , each message symbol or channel symbol takes the form of a baseband waveform gi(t) , where i=1,2,3,…,M. In any electronic implementation, the bit stream, prior to pulse-modulation, is represented with voltage levels. One might wonder why there is a separate block for pulse modulation when in face different voltage levels for binary ones and zeros can be viewed as impulse or as ideal rectangular pulses, each pulse occupying one bit time. There are two important differences between such voltage levels and the baseband waveforms used for modulation. First, the pulse-modulation block allows for a variety of binary and M-ary pulse-waveform types. Second, the filtering within the pulse-modulation block yields pulses that occupy more than just time. Filtering yields pulses that are spread in time, thus the pulses are “smeared” into neighboring bit-times. This filtering is sometimes referred to as pulse shaping; it is used to contain the transmission bandwidth within some desired spectral region.
For an application involving RF transmission, the text important step is bandpass modulation; it is required whenever the transmission medium will not support the propagation of pulse-like waveforms. For such cases, the medium requires a bandpass waveform si(t), where i=1,2,…,M. The term bandpass is used to indicate that the baseband waveform gi(t) is frequency translate by a carrier wave to a frequency that is much larger than the spectral content of gi(t). As si(t) propagates over the hannel, it is impated by the channel characteristics, which can be described in term of the channel’s impulse response hc(t). Also, at various point along the signal route, additive random noise distorts the received signal r(t), so that its reception must be termed a corrupted version of the signal si(t) that was launched at the transmitter. The received signal r(t) can be expressed as:
r(t)= si(t)* hc(t)+n(t) i=1,2,…,M.
where “*” respresents a convolution operation, and n(t) represents a noise.
In the reverse direction, the receiver front end and/or the demodulator provides frequency down-conversion for each bandpass waveform r(t). The demodulator restores r(t) to an optimally shaped baseband pulse z(t) in preparation for detection. Typically, there can be several filters associated with the receiver and demodulator filtering to remove unwanted high frequency terms (in the frequency down-conversion of bandpass waveforms), and filtering for pulse shaping. Equalization can be described as a filtering option that is used in or after the demodulator to reverse any degrading effects on the signal that were caused by the channel. Equalization becomes essential whenever the impulse reponse of the channel hc(t), is so poor that the received signal is badly distortion caused. An equalizer is implement to compensate for (i.e., remove or diminish) any signal distortion caused by a nonideal hc(t). Finally, the sampling step transforms the shaped pulse z(t) to a sample z(t), and the detection step transforms z(t) to an estimate of the channel symbol ui or an estimate of the message symbol mi (if there is no channel coding). As we known,demodulation is degrading the digital meaning of that waveform.
The other signal processing steps within the modern are design option for specific system needs. Source coding produces analog-to-digital (A/D) conversion (for analog sources) and removes redundant (unneeded) information. Note that a typical DCS would either use the source coding option (for both digitizing and compressing the source information ), or it wpuld either use the simpler formatting transformation(for digitizing alone). A system would not use both source coding and formatting, because the former already includes the essential step of digitizing the information. Encryption, which is used to provide communication privacy, prevents unauthorized users from understanding message and from injecting false message into the system. Channel coding, for a given data rate, can reduce the probability of error, PE, or reduce the required signal-to-noise ratio to achieve a desired PE at the expense of transmission bandwidth or decoder complexity. Multiplexing and multiple-access procedures combine signals that might have different characteristics or might originate from different sources, so that they can share a portion of the communications resource(e.g., spectrum, time). Frequency spreading can produce a signal that is relatively invulnerable to interference (both natural and intentional) and can be used to enhance the privacy of the communications. It is also a valuable technique used for multiple access.