module shoumaiji (clk,a,b,duanxuan,weixuan,out,out1)
input clk
input a,b//a为投入0.5元信号,b为投入1元信号
output [8:1]duanxuan//输出8位段选信号
output weixuan//输出1位位选信号
output out //out为高电平时售卖机闸门打开,汽水掉出来
output out1 //out1为高电平时候找0.5元
reg weixuan
reg [8:1]duanxuan
reg [31:0]count//数码管动态扫描计数
reg [31:0]count1//用于计算售卖机闸门打开时间
reg [4:1]a1,b1 //用a1,b1寄存投入的0.5元和1元硬币数目
reg out,out1
always @(posedge a or posedge out)
begin
if(out==1) a1<=0//汽水出来后计数值清零
else a1<=a1+4'b1
end
always @(posedge b or posedge out)
begin
if(out==1) b1<=0//汽水出来后计数值清零
else b1<=b1+4'b1
end
always@(posedge clk) //1KHz时钟
begin
if(a1==5) out<=1 //因为汽水为2.5,可以给5个0.5元
else if(a1==3&&b1==1) out<=1//可以给3个0.5元和1个1元
else if(a1==1&&b1==2) out<=1//,可以给1个0.5元和2个1元
else if(b1==3)begin out<=1out1<=1end//可以给3个一块的,系统找回0.5元
else if(a1==0&&b1==0) //如果没人投币,则两位数码管显示0
begin
if(count==50) //如果实际运行中发现数码管有闪烁,可以将此数值调小
begin
weixuan<=1'b0
duanxuan<=8'b00111111//0
end
if(count==100) //如果实际运行中发现数码管有闪烁,可以将此数值调小
begin
weixuan<=1'b1
duanxuan<=8'b00111111//0
count<=0
end
end
else if(a==1)//投币0.5元,显示0.5,假设数码管为共阴极的
begin
count<=count+1
if(count==50) //如果实际运行中发现数码管有闪烁,可以将此数值调小
begin
weixuan<=1'b0
duanxuan<=8'b01101101//5
end
if(count==100) //如果实际运行中发现数码管有闪烁,可以将此数值调小
begin
weixuan<=1'b1
duanxuan<=8'b10111111//0.
count<=0
end
end
else if(b==1) //投币1元,显示01
begin
count<=count+1
if(count==50) //如果实际运行中发现数码管有闪烁,可以将此数值调小
begin
weixuan<=1'b0
duanxuan<=8'b00000110//1
end
if(count==100) //如果实际运行中发现数码管有闪烁,可以将此数值调小
begin
weixuan<=1'b1
duanxuan<=8'b00111111//0
count<=0
end
end
if(out==1)
begin
if(count1==3000)//让闸门打开3秒,由于为1KHz时钟,故要数3000下
begin
out<=0
out1<=0
count1<=0
end
else count1<=count1+1
end
end
endmodule
import java.util.Scannerpublic class Shop
{
private String coffee="咖啡"
private String coke="可乐"
private String tea="茶"
private double coffeeprice=2.00
private double cokeprice=3.00
private double teaprice=5
private double price=0.0
public Shop()
{
}
public void getName(int i)
{
if(i==1)
{
System.out.println("你选择的是咖啡")
}
if(i==2)
{
System.out.println("你选择的是可乐")
}
if(i==3)
{
System.out.println("你选择的是茶")
}
}
public double getShopping(int i,double p)
{
if(i==1)
{
if(p<coffeeprice)
{
System.out.println("您的钱不够买此商品")
}
else
{
price=p-coffeeprice
}
}
if(i==2)
{
if(p<cokeprice)
{
System.out.println("您的钱不够买此商品")
}
else
{
price=p-cokeprice
}
}
if(i==3)
{
if(p<teaprice)
{
System.out.println("您的钱不够买此商品")
}
else
{
price=p-teaprice
}
}
return price
}
public static void main(String[] args)
{
Shop shop=new Shop()
try
{
System.out.println("请选择你想要的商品\n 1.咖啡 2.可乐 3.茶")
Scanner si=new Scanner(System.in)
int i=si.nextInt()
System.out.println(" ")
if(i>3||i<1)
{
System.out.println("没有此产品")
}
else
{
shop.getName(i)
System.out.println(" ")
System.out.print("请付账:")
Scanner sp=new Scanner(System.in)
double p=sp.nextDouble()
System.out.println(" ")
if(shop.getShopping(i,p)!=0.0)
{
System.out.println("找你的钱:"+shop.getShopping(i,p))
}
}
}
catch(Exception ex)
{
System.out.println("请正确输入!")
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)