我是个新手,最近看了一个UART的源程序,有个关于发送移位寄存器的地方不是很明白,请高手教教我。部分程序如下:
-- transmit shift register:
txshift:
PROCESS (reset, txclk)
BEGIN
IF reset='1' THEN
txreg <= (OTHERS=>'0') ;
txtag1 <= '0' ;
txtag2 <= '0' ;
txparity <= '0' ;
tx <= '0' ;
ELSIF txclk'event AND txclk = '1' THEN
IF (txdone AND txdatardy) = '1' THEN
-- Initialize registers and load next byte of data
txreg <= txhold; -- Load tx register from txhold
txtag2 <= '1'; -- Tag bits for detecting
txtag1 <= '1'; -- when shifting is done
txparity <= '1'; -- Parity bit.Initializing to 1==odd parity
tx <= '0'; -- Start bit
ELSE
-- Shift data
txreg <= txreg(1 TO 7) & txtag1;
txtag1 <= txtag2;
txtag2 <= '0';
-- Form parity as each bit goes by
txparity <= txparity XOR txreg(0);
-- Shift out data or parity bit or stop/idle bit
IF txdone = '1' THEN
tx <= '1'; -- stop/idle bit
ELSIF paritycycle = '1' THEN
tx <= txparity; -- Parity bit
ELSE
tx <= txreg(0); --Shift data bit
END IF;
END IF ;
END IF;
END PROCESS;
-- paritycycle = 1 on next to last cycle (When txtag2 has reached txreg(1))
-- (Enables putting the parity bit out on tx)
paritycycle <= txreg(1) AND NOT (txtag2 OR txtag1 OR
txreg(7) OR txreg(6) OR txreg(5) OR
txreg(4) OR txreg(3) OR txreg(2));
-- txdone = 1 when done shifting (When txtag2 has reached tx)
txdone <= NOT (txtag2 OR txtag1 OR
txreg(7) OR txreg(6) OR txreg(5) OR txreg(4) OR
txreg(3) OR txreg(2) OR txreg(1) OR txreg(0));
其中有这样一个问题:
假设txreg<=txhold的初值是10101010(0~7)
那么经过txreg <= txreg(1 TO 7) & txtag1以后不就变成了0101010+txtag1(0~7)了吗?
这时的txreg(0)=0,而不是‘1’
先移位再计算校验位txparity<= txparity XOR txreg(0)的话不就把原来的第一位丢了吗?算出的校验位还对吗?
这是怎么回事啊?是我哪理解错了吗?
请大虾指点!~~