问答

汇集网友智慧,解决技术难题

21ic问答首页 - TAG - counter
  • 求助! sos

    我写的这个函数,是想要完成 [font=等线][size=12pt]按下一次对应按键时,LED 以 5Hz 频率闪烁 (代表进门)[/size][/font] [font=等线][size=12pt],双击对应按键时,LED 以 2Hz 频率闪烁(代表出门),每个门[/size][/font] [font=等线][size=12pt]最多可以进入三次,超出进入上限时 LED 常亮 5s;这个任务,但是我发现我·按下按键后第一次能进门,第二次时就进不去了,试了好久也没改出来。求大佬帮帮[/size][/font] #include void Timer01Init() { TMOD = 0x11; //令T0,T1的M1,M0分别为0,1.启用16定时器0,1,启用TL,TH TL0 = 0xD8; //1ms,11.0592Hz TH0 = 0xF0; TL1 = 0xD8; TH1 = 0xF0; TF0 = 0; //溢出中断标志位,为1时向cpu请求中断; TF1 = 0; TR0 = 1; //先禁止定时器计数,按下按键才允许计数;1允许 TR1 = 1; EA = 1; //总中断允许控制位; ET0 = 1; //溢出中断允许位; ET1 = 1; PT0 = 1; //优先级; } #include #include "Timer01Init.h" #define red P1_0 //#define yellow P1_1 //#define blue P1_3 unsigned char A , C , LEDtime , GateNumr , GateNumy , GateNumb , sure , Gatered , Gateyellow , Gateblue ; //B; unsigned char Mode ; unsigned int counter ; void main() { ///////////////////////red Timer01Init(); while(1) { if(P3_1 == 0) //这里有问题 :我不加 && Gatered == 1这个函数可以执行,我加上之后我没想明白为啥会运行不了。 //5Hz,进门 { if(GateNumr < 3) //门只能进入三次 { if(counter >= 100) { counter = 0; red = !red; LEDtime++; } if(LEDtime >= 6) //P1_2亮一个周期LEDtime会加两次,所以LEDtime不为3; { // LCD12864_show_string(1,0,"red"); LEDtime = 0; GateNumr++; TR1 = 0; A = 0; B = 0; C = 0; } }else //进门超出三次常亮5秒 { counter = 0; while(counter <= 5000) //不是5秒? { red = 0 ; } red = 1; GateNumr = 0; counter = 0; TR1 = 0; } } if(C == 2) //2Hz, 出门 { if(GateNumr <= 3) { // LCD12864_show_string(0,1,"KeyPress(P3_1)"); if(counter >= 250) { counter = 0; red = !red; LEDtime++; } if(LEDtime >= 6) //P1_2亮一个周期LEDtime会加两次,所以LEDtime不为3; { LEDtime = 0; GateNumr--; TR1 = 0; A = 0; B = 0; C = 0; } } } Gatered = 0; } }

    MR counter TI LED TE 单片机

    1869浏览量 0回复量 关注量
  • FPGA程序,不能正确输出,各位帮忙看下

    我编写了两个文件,配置了输出口,,LASER_PWM 始终输出不了波形,请问下,这个是什么原因呀?modesiem仿真是有波形输出的//////////////-------PWM.V 文件 `timescale 1 ns / 1 ps module pwm( input rsn, input clk, input [15:0]pwm_counter, input [15:0]pwm_duty, output pwm_out ); //reg[15:0]pwm_counter; //reg [15:0]pwm_duty; reg [15:0]counter=16'd0; reg pwm_out_r; always@(posedge clk or negedge rsn) //begin if(!rsn) begin counter <= 16'd0; end else begin if(counter >= pwm_counter)counter <= 16'd0; else counter <= counter + 1'd1; end // end always@(posedge clk or negedge rsn) if(!rsn) begin pwm_out_r <= 1'd0; end else if(counter>=pwm_duty) pwm_out_r<=1'b0; else pwm_out_r<=1'b1; //wire pwm_out; assign pwm_out = pwm_out_r;//((counter > pwm_duty) ? 1'd0 : 1'd1); endmodule ////// top_indepen.v 文件 //-------------------------Timescale----------------------------// `timescale 1 ns / 1 ps //--------------------FSMC_SIG---------------------// module FSMC_INDEP( FPGA_CLK, //鏉堟挸鍙嗛弶鑳祰閺呰埖灏烥PGA_CLK,25M FPGA_LEDR, FPGA_LEDG, FPGA_LEDB, WR, //FSMC閸愭瑤淇婇崣 RD, //FSMC鐠囪淇婇崣 CS0, //FSMC閻楀洭鈧 A, //FSMC閸︽澘**冮幀鑽ゅ殠 DB, //FSMC閺佺増宓侀幀鑽ゅ殠 NADV, //FSMC閻ㄥ嚞ADV //LASER PWM LASER_PWM, //interpn_exti Interp_ex, testclk, testclk_100, testclk_50, FPGA_KEY ); input FPGA_KEY; input FPGA_CLK,NADV; input WR,RD,CS0; inout [15:0]DB; input [24:16]A; output FPGA_LEDB,FPGA_LEDG,FPGA_LEDR; assign FPGA_LEDR = 1'd1; assign FPGA_LEDG = 1'd0; assign FPGA_LEDB = 1'd1; output LASER_PWM; output Interp_ex,testclk,testclk_100,testclk_50; //-------------------------MY_PLL-------------------------------// wire PLL_100M; wire PLL_8M; wire PLL_50M; wire PLL_12_5M; reg LaserCtrl1; reg [15:0] dbPower1;//閸旂喓宸 閸楃姷鈹栧В reg [15:0]dbQFreq1;//妫版垹宸 reg [15:0]counter; initial begin dbQFreq1 <= 16'd106; dbPower1 <= 16'd53; LaserCtrl1 <= 1'd1; end MY_PLL U1( .inclk0(FPGA_CLK), .c0(PLL_100M), .c1(PLL_50M), .c2(PLL_8M), .c3(PLL_12_5M) );// //------------------------RST_Ctrl-----------------------------// wire RST_n; RST_Ctrl U2( .FPGA_CLK(FPGA_CLK), .RST_n(RST_n) ); //娓氬瀵睷ST_Ctrl濡€虫健,鏉堟挸鍤崗銊ョ湰婢跺秳缍呮穱鈥冲娇RST_n pwm U5( .rsn(RST_n), .clk(PLL_8M), .pwm_counter(dbQFreq1), .pwm_duty(dbPower1),//閸旂喓宸 .pwm_out(LASER_PWM) ); endmodule

    FPGA PWM counter TE npu

    924浏览量 2回复量 关注量