日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁 > 單片機(jī) > 單片機(jī)
[導(dǎo)讀] 1 library ieee; 2 3 use ieee.std_logic_1164.all; 4 5 use ieee.std_logic_arith.all; 6 7 use ieee.std_logic_unsigned.all; 8 9 1011 entity KBCtest is1213 port(1415 rst,clk:instd_logic;--時鐘和復(fù)位信號16

1 library ieee;

2

3 use ieee.std_logic_1164.all;

4

5 use ieee.std_logic_arith.all;

6

7 use ieee.std_logic_unsigned.all;

8

9

10

11 entity KBCtest is

12

13 port(

14

15 rst,clk:instd_logic;--時鐘和復(fù)位信號

16

17 --AVR 讀寫相關(guān)信號線

18

19 ale,rd,wr:instd_logic;--地址鎖存、讀、寫信號

20

21 ad:inoutstd_logic_vector(7 downto 0);--地址數(shù)據(jù)信號線

22

23

24

25 --指示燈

26

27 led1,led2:outstd_logic;

28

29

30

31 --PWM

32

33 pwm1,pwm2:outstd_logic

34

35

36

37 --放大增益控制

38

39

40

41 --AD8364讀寫操作信號線

42

43 );

44

45 end KBCtest;

46

47

48

49 architecture art of KBCtest is

50

51 ------------------------------------------------全局信號定義-------------------------------------------------------------------

52

53 --AVR訪問操作相關(guān)信號

54

55 signal adr: std_logic_vector(7 downto 0); --地址寄存器

56

57 signal data_buf: std_logic_vector(7 downto 0);

58

59 signal data_outctl:std_logic;

60

61

62

63

64

65 --pwm部分相關(guān)寄存器定義 寄存器暫時定義為8位

66

67 signal pwmfreq_reg:std_logic_vector(7 downto 0);

68

69 signal pwmocr1_reg:std_logic_vector(7 downto 0);

70

71 signal pwmocr2_reg:std_logic_vector(7 downto 0);

72

73

74

75 signal pwm_cnt:std_logic_vector(7 downto 0);

76

77

78

79 --時鐘分頻相關(guān)變量

80

81 signal clkcnt:std_logic_vector(16 downto 0);

82

83 signal adc_clk:std_logic;--ADC時鐘信號

84

85 signal pwm_clk:std_logic;--pwm時鐘信號

86

87

88

89 --led指示相關(guān)變量

90

91 signal led_clk:std_logic;--led時鐘信

92

93 signal led1_cnt:std_logic_vector(7 downto 0);

94

95 signal led2_cnt:std_logic_vector(7 downto 0);

96

97 signal led1s:std_logic;

98

99 signal led2s:std_logic;

100

101

102

103 begin

104

105

106

107 ------------------------------------------------時鐘分頻-------------------------------------------------------------------

108

109 process(rst,clk) is

110

111 begin

112

113 if rst='0' then

114

115 clkcnt <= "00000000000000000";

116

117 elsif(clk'event and clk = '1') then

118

119 if(clkcnt = "11111111111111111") then

120

121 clkcnt<= "00000000000000000";

122

123 else

124

125 clkcnt <= clkcnt+1;

126

127 end if;

128

129 end if;

130

131 end process;

132

133 pwm_clk <= clkcnt(7);--分頻PWM時鐘

134

135 led_clk <= clkcnt(16);--分頻LED時鐘

136

137

138

139 ------------------------------------------------AVR訪問操作----------------------------------------------------------------

140

141 data_outctl <= (not ale) and (not rd) and (wr);

142

143 ad <= data_buf when (data_outctl='1') else "ZZZZZZZZ";

144

145

146

147 --鎖存AVR地址數(shù)據(jù)

148

149 process(rst,ale) is

150

151 begin

152

153 if rst='0' then

154

155 adr <= "00000000";

156

157 elsif(ale'event and ale='0') then--在ale信號的下降沿鎖存地址數(shù)據(jù)

158

159 adr <= ad;

160

161 end if;

162

163 end process;

164

165

166

167 -------------------------------------AVR寫數(shù)據(jù)-----------------------------------

168

169 process(rst,wr,ale) is

170

171 begin

172

173 if rst='0' then--對各寄存器給定初值

174

175 pwmfreq_reg<="11111111";

176

177 pwmocr1_reg<="10000000";

178

179 elsif (wr='1' and wr'event) then--在wr信號上升沿進(jìn)行寫操作

180

181 if ale = '0' then

182

183 case adr is

184

185 when "00000001" =>pwmfreq_reg<=ad;

186

187 when "00000010" =>pwmocr1_reg<=ad;

188

189

190

191 when others =>

192

193 pwmfreq_reg <= pwmfreq_reg;

194

195

196

197 end case;

198

199 end if;

200

201 end if;

202

203 end process;

204

205

206

207 ------------------------------------AVR讀數(shù)據(jù)-------------------------------------

208

209 process(rst,rd,ale) is

210

211 begin

212

213 if rst='0' then

214

215 data_buf<="00000000";

216

217 elsif (rd='0'and rd'event) then

218

219 case adr is

220

221 when "00000001" => data_buf <=pwmfreq_reg;

222

223 when "00000010" => data_buf <=pwmocr1_reg;

224

225 when "00000011" => data_buf <="00110011";

226

227 when others =>

228

229 data_buf <= "ZZZZZZZZ";

230

231 end case;

232

233 end if;

234

235 end process;

236

237 ------------------------------------LED指示-------------------------------------

238

239 process(led_clk)is

240

241 begin

242

243 if(led_clk'event and led_clk='1') then

244

245 led1_cnt <= led1_cnt+1;

246

247 if (led1_cnt >=pwmfreq_reg) then

248

249 led1s <= NOT led1s;

250

251 led1_cnt <="00000000";

252

253 end if;

254

255 end if;

256

257 end process;

258

259 led1<=led1s;

260

261 process(led_clk)is

262

263 begin

264

265 if(led_clk'event and led_clk='1') then

266

267 led2_cnt <= led2_cnt+1;

268

269 if (led2_cnt >=pwmocr1_reg) then

270

271 led2s <= NOT led2s;

272

273 led2_cnt <="00000000";

274

275 end if;

276

277 end if;

278

279 end process;

280

281 led2<=led2s;

282

283

284

285 --------------------------------------PWM---------------------------------------

286

287 process(pwm_clk) is

288

289 begin

290

291 if rst='0' then

292

293 pwm_cnt<="00000000";

294

295 elsif(pwm_clk'event and pwm_clk='1') then

296

297 if(pwm_cnt > pwmfreq_reg) then

298

299 pwm_cnt <= "00000000";

300

301 else

302

303 pwm_cnt<=pwm_cnt+1;

304

305 end if;

306

307

308

309 --數(shù)據(jù)比較模塊

310

311 if(pwm_cnt>=pwmocr1_reg) then

312

313 pwm1<= '1';

314

315 else

316

317 pwm1<= '0';

318

319 end if;

320

321 end if;

322

323 end process;

324

325 end;

326

327


本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉