Begin to sell

2004年9月7日,主要代码经多次修改后告一段落并正式上传,随后将开始进军海外市场。

  Today is sep7 2004.把主要代码修改了好几次。终于告一段落。正式上传。开始进军海外了。

// vending-machine // 2 yuan for a bottle of drink // only 2 coins supported: 5 jiao and 1 yuan // finish the function of selling and changing module vending_machine_p3 ( input clk , input rstn , input [1:0] coin , //01 for 0.5 jiao, 10 for 1 yuan output [1:0] change , output sell //output the drink ); //machine state decode parameter IDLE = 3'd0 ; parameter GET05 = 3'd1 ; parameter GET10 = 3'd2 ; parameter GET15 = 3'd3 ; //machine variable reg [2:0] st_next ; reg [2:0] st_cur ; //(1) state transfer always @(posedge clk or negedge rstn) begin if (!rstn) begin st_cur <= 'b0 ; end else begin st_cur <= st_next ; end end //(2) state switch, using block assignment for combination-logic //all case items need to be displayed completely always @(*) begin //st_next = st_cur ;//如果条件选项考虑不全,可以赋初值消除latch case(st_cur) IDLE: case (coin) 2'b01: st_next = GET05 ; 2'b10: st_next = GET10 ; default: st_next = IDLE ; endcase GET05: case (coin) 2'b01: st_next = GET10 ; 2'b10: st_next = GET15 ; default: st_next = GET05 ; endcase GET10: case (coin) 2'b01: st_next = GET15 ; 2'b10: st_next = IDLE ; default: st_next = GET10 ; endcase GET15: case (coin) 2'b01,2'b10: st_next = IDLE ; default: st_next = GET15 ; endcase default: st_next = IDLE ; endcase end //(3) output logic, using non-block assignment reg [1:0] change_r ; reg sell_r ; always @(posedge clk or negedge rstn) begin if (!rstn) begin change_r <= 2'b0 ; sell_r <= 1'b0 ; end else if ((st_cur == GET15 && coin ==2'h1) || (st_cur == GET10 && coin ==2'd2)) begin change_r <= 2'b0 ; sell_r <= 1'b1 ; end else if (st_cur == GET15 && coin == 2'h2) begin change_r <= 2'b1 ; sell_r <= 1'b1 ; end else begin change_r <= 2'b0 ; sell_r <= 1'b0 ; end end assign sell = sell_r ; assign change = change_r ; endmodule 解释这段verilog代码
09-16
/* * Brian R Taylor * brian.taylor@bolderflight.com * * Copyright (c) 2022 Bolder Flight Systems Inc * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the “Software”), to * deal in the Software without restriction, including without limitation the * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ #include "sbus.h" /* SBUS object, reading SBUS */ bfs::SbusRx sbus_rx(&Serial2); /* SBUS object, writing SBUS */ bfs::SbusTx sbus_tx(&Serial2); /* SBUS data */ bfs::SbusData data; void setup() { /* Serial to display data */ Serial.begin(115200); while (!Serial) {} /* Begin the SBUS communication */ sbus_rx.Begin(); sbus_tx.Begin(); } void loop () { if (sbus_rx.Read()) { /* Grab the received data */ data = sbus_rx.data(); /* Display the received data */ for (int8_t i = 0; i < data.NUM_CH; i++) { Serial.print(data.ch[i]); Serial.print("\t"); } /* Display lost frames and failsafe data */ Serial.print(data.lost_frame); Serial.print("\t"); Serial.println(data.failsafe); /* Set the SBUS TX data to the received data */ sbus_tx.data(data); /* Write the data to the servos */ sbus_tx.Write(); } } 此SBUS代码映射值是什么范围?
10-05
module vending_machine ( input clk, input rstn, input [1:0] coin, // 00:无输入 01:1元 10:2元 11:非法 output reg sell, // 出货信号 output reg [1:0] change // 找零金额(00:0元 01:1元) ); // 状态编码 parameter S0 = 3'b000; parameter S1 = 3'b001; parameter S2 = 3'b010; parameter S3 = 3'b011; // 3元(出货) parameter S4 = 3'b100; // 4元(出货+找零) reg [2:0] current_state, next_state; // 状态寄存器 always @(posedge clk or negedge rstn) begin if (!rstn) current_state <= S0; else current_state <= next_state; end // 状态转移逻辑 always @(*) begin next_state = current_state; // 默认保持当前状态 case (current_state) S0: case (coin) 2'b01: next_state = S1; // 投入1元→S1 2'b10: next_state = S2; // 投入2元→S2 default: next_state = S0; endcase S1: case (coin) 2'b01: next_state = S2; // 投入1元→S2 2'b10: next_state = S3; // 投入2元→S3 default: next_state = S1; endcase S2: case (coin) 2'b01: next_state = S3; // 投入1元→S3 2'b10: next_state = S4; // 投入2元→S4 default: next_state = S2; endcase S3, S4: next_state = S0; // 交易完成,返回初始状态 default: next_state = S0; endcase end // 输出逻辑(Moore型) always @(posedge clk or negedge rstn) begin if (!rstn) begin sell <= 1'b0; change <= 2'b00; end else begin case (current_state) S3: begin // 3元状态:出货,不找零 sell <= 1'b1; change <= 2'b00; end S4: begin // 4元状态:出货,找1元 sell <= 1'b1; change <= 2'b01; end default: begin // 其他状态:无输出 sell <= 1'b0; change <= 2'b00; end endcase end end endmodule 设计一段这段代码的tesybench
最新发布
10-27
/* Copyright 2018 Paul Stoffregen * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * software and associated documentation files (the "Software"), to deal in the Software * without restriction, including without limitation the rights to use, copy, modify, * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include <Arduino.h> #include "Ethernet.h" #include "utility/w5100.h" #include "Dhcp.h" IPAddress EthernetClass::_dnsServerAddress; DhcpClass* EthernetClass::_dhcp = NULL; int EthernetClass::begin(uint8_t *mac, unsigned long timeout, unsigned long responseTimeout) { static DhcpClass s_dhcp; _dhcp = &s_dhcp; // Initialise the basic info if (W5100.init() == 0) return 0; SPI.beginTransaction(SPI_ETHERNET_SETTINGS); W5100.setMACAddress(mac); W5100.setIPAddress(IPAddress(0,0,0,0).raw_address()); SPI.endTransaction(); // Now try to get our config info from a DHCP server int ret = _dhcp->beginWithDHCP(mac, timeout, responseTimeout); if (ret == 1) { // We've successfully found a DHCP server and got our configuration // info, so set things accordingly SPI.beginTransaction(SPI_ETHERNET_SETTINGS); W5100.setIPAddress(_dhcp->getLocalIp().raw_address()); W5100.setGatewayIp(_dhcp->getGatewayIp().raw_address()); W5100.setSubnetMask(_dhcp->getSubnetMask().raw_address()); SPI.endTransaction(); _dnsServerAddress = _dhcp->getDnsServerIp(); socketPortRand(micros()); } return ret; } void EthernetClass::begin(uint8_t *mac, IPAddress ip) { // Assume the DNS server will be the machine on the same network as the local IP // but with last octet being '1' IPAddress dns = ip; dns[3] = 1; begin(mac, ip, dns); } void EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns) { // Assume the gateway will be the machine on the same network as the local IP // but with last octet being '1' IPAddress gateway = ip; gateway[3] = 1; begin(mac, ip, dns, gateway); } void EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway) { IPAddress subnet(255, 255, 255, 0); begin(mac, ip, dns, gateway, subnet); } void EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet) { if (W5100.init() == 0) return; SPI.beginTransaction(SPI_ETHERNET_SETTINGS); W5100.setMACAddress(mac); #ifdef ESP8266 W5100.setIPAddress(&ip[0]); W5100.setGatewayIp(&gateway[0]); W5100.setSubnetMask(&subnet[0]); #elif ARDUINO > 106 || TEENSYDUINO > 121 W5100.setIPAddress(ip._address.bytes); W5100.setGatewayIp(gateway._address.bytes); W5100.setSubnetMask(subnet._address.bytes); #else W5100.setIPAddress(ip._address); W5100.setGatewayIp(gateway._address); W5100.setSubnetMask(subnet._address); #endif SPI.endTransaction(); _dnsServerAddress = dns; } void EthernetClass::init(uint8_t sspin) { W5100.setSS(sspin); } EthernetLinkStatus EthernetClass::linkStatus() { switch (W5100.getLinkStatus()) { case UNKNOWN: return Unknown; case LINK_ON: return LinkON; case LINK_OFF: return LinkOFF; default: return Unknown; } } EthernetHardwareStatus EthernetClass::hardwareStatus() { switch (W5100.getChip()) { case 51: return EthernetW5100; case 52: return EthernetW5200; case 55: return EthernetW5500; default: return EthernetNoHardware; } } int EthernetClass::maintain() { int rc = DHCP_CHECK_NONE; if (_dhcp != NULL) { // we have a pointer to dhcp, use it rc = _dhcp->checkLease(); switch (rc) { case DHCP_CHECK_NONE: //nothing done break; case DHCP_CHECK_RENEW_OK: case DHCP_CHECK_REBIND_OK: //we might have got a new IP. SPI.beginTransaction(SPI_ETHERNET_SETTINGS); W5100.setIPAddress(_dhcp->getLocalIp().raw_address()); W5100.setGatewayIp(_dhcp->getGatewayIp().raw_address()); W5100.setSubnetMask(_dhcp->getSubnetMask().raw_address()); SPI.endTransaction(); _dnsServerAddress = _dhcp->getDnsServerIp(); break; default: //this is actually an error, it will retry though break; } } return rc; } void EthernetClass::MACAddress(uint8_t *mac_address) { SPI.beginTransaction(SPI_ETHERNET_SETTINGS); W5100.getMACAddress(mac_address); SPI.endTransaction(); } IPAddress EthernetClass::localIP() { IPAddress ret; SPI.beginTransaction(SPI_ETHERNET_SETTINGS); W5100.getIPAddress(ret.raw_address()); SPI.endTransaction(); return ret; } IPAddress EthernetClass::subnetMask() { IPAddress ret; SPI.beginTransaction(SPI_ETHERNET_SETTINGS); W5100.getSubnetMask(ret.raw_address()); SPI.endTransaction(); return ret; } IPAddress EthernetClass::gatewayIP() { IPAddress ret; SPI.beginTransaction(SPI_ETHERNET_SETTINGS); W5100.getGatewayIp(ret.raw_address()); SPI.endTransaction(); return ret; } void EthernetClass::setMACAddress(const uint8_t *mac_address) { SPI.beginTransaction(SPI_ETHERNET_SETTINGS); W5100.setMACAddress(mac_address); SPI.endTransaction(); } void EthernetClass::setLocalIP(const IPAddress local_ip) { SPI.beginTransaction(SPI_ETHERNET_SETTINGS); IPAddress ip = local_ip; W5100.setIPAddress(ip.raw_address()); SPI.endTransaction(); } void EthernetClass::setSubnetMask(const IPAddress subnet) { SPI.beginTransaction(SPI_ETHERNET_SETTINGS); IPAddress ip = subnet; W5100.setSubnetMask(ip.raw_address()); SPI.endTransaction(); } void EthernetClass::setGatewayIP(const IPAddress gateway) { SPI.beginTransaction(SPI_ETHERNET_SETTINGS); IPAddress ip = gateway; W5100.setGatewayIp(ip.raw_address()); SPI.endTransaction(); } void EthernetClass::setRetransmissionTimeout(uint16_t milliseconds) { if (milliseconds > 6553) milliseconds = 6553; SPI.beginTransaction(SPI_ETHERNET_SETTINGS); W5100.setRetransmissionTime(milliseconds * 10); SPI.endTransaction(); } void EthernetClass::setRetransmissionCount(uint8_t num) { SPI.beginTransaction(SPI_ETHERNET_SETTINGS); W5100.setRetransmissionCount(num); SPI.endTransaction(); } EthernetClass Ethernet; 这里面有配置spi0引脚的代码吗
06-06
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值