#include "system.h"
#include <stdio.h>
#include "sys/alt_irq.h"
#include "seller_sw.h"
int type = 0;
int coin_in = 0;
int charge = 0;
int cancel = 0;
int reset = 0;
void ISR_coin(void* context, unsigned long id)
{
if (COIN->DATA == 1) coin_in = coin_in + 10;
else if (COIN->DATA == 2) coin_in = coin_in + 5;
else if (COIN->DATA == 4) coin_in = coin_in + 1;
else coin_in = coin_in;
COIN->EDGE_CAPTURE = 0;
}
void init_coin(void)
{
COIN->INTERRUPT_MASK = 7;
alt_irq_register(COIN_IRQ, NULL, ISR_coin);
}
void ISR_cancel(void* context, unsigned long id)
{
if (CANCEL->DATA == 1)
cancel = 1;
else cancel = 0;
CANCEL->EDGE_CAPTURE = 0;
}
void init_cancel(void)
{
CANCEL->INTERRUPT_MASK = 1;
alt_irq_register(CANCEL_IRQ, NULL, ISR_cancel);
}
void ISR_reset(void* context, unsigned long id)
{
if (RESET->DATA == 1)
reset = 1;
else reset = 0;
RESET->EDGE_CAPTURE = 0;
}
void init_reset(void)
{
RESET->INTERRUPT_MASK = 1;
alt_irq_register(RESET_IRQ, NULL, ISR_reset);
}
int hex_display(int i)
{
int j = 64;
switch(i)
{
case 0:
j = 64;
break;
case 1:
j = 121;
break;
case 2:
j = 36;
break;
case 3:
j = 48;
break;
case 4:
j = 25;
break;
case 5:
j = 18;
break;
case 6:
j = 2;
break;
case 7:
j = 120;
break;
case 8:
j = 0;
break;
case 9:
j = 16;
break;
}
return j;
}
void main()
{
init_coin();
init_cancel();
init_reset();
while(1)
{
//type select
if (PRICE->DATA == 1) type = 20;
else if (PRICE->DATA == 2) type = 14;
else if (PRICE->DATA == 4) type = 10;
else type = 0;
//price display
HEX7->DATA = hex_display(type/10);
HEX6->DATA = hex_display(type%10);
if(reset == 0)
{
if(cancel == 0)
{
if (coin_in < type)
{
charge = 0;
READY->DATA = 0;
DRINK_OUT->DATA = 0;
//input coin display
HEX5->DATA = hex_display(coin_in/10);
HEX4->DATA = hex_display(coin_in%10);
HEX2->DATA = hex_display(charge/10);
HEX1->DATA = hex_display(charge/5 - charge/10 - charge/10);
HEX0->DATA = hex_display(charge%5);
}
else if(coin_in >= type && type > 0)
{
charge = coin_in - type;
READY->DATA = 1;
DRINK_OUT->DATA = 1;
HEX5->DATA = hex_display(coin_in/10);
HEX4->DATA = hex_display(coin_in%10);
HEX2->DATA = hex_display(charge/10);
HEX1->DATA = hex_display(charge/5 - charge/10 - charge/10);
HEX0->DATA = hex_display(charge%5);
}
}
else
{
READY->DATA = 0;
DRINK_OUT->DATA = 0;
HEX5->DATA = hex_display(0);
HEX4->DATA = hex_display(0);
HEX2->DATA = hex_display(coin_in/10);
HEX1->DATA = hex_display(coin_in/5 - coin_in/10 - coin_in/10);
HEX0->DATA = hex_display(coin_in%5);
coin_in = 0;
charge = 0;
cancel = 0;
}
}
else
{
READY->DATA = 0;
coin_in = 0;
charge = 0;
cancel = 0;
reset = 0;
HEX5->DATA = hex_display(coin_in/10);
HEX4->DATA = hex_display(coin_in%10);
HEX2->DATA = hex_display(charge/10);
HEX1->DATA = hex_display(charge/5 - charge/10 - charge/10);
HEX0->DATA = hex_display(charge%5);
}
}
return 0;
}
why_900109
- 粉丝: 3
- 资源: 7
最新资源
- 基于粒子群优化算法的微型燃气轮机冷热电联供系统优化调度附Matlab代码.rar
- 基于企鹅优化算法的机器人轨迹规划Matlab代码.rar
- 基于无人机的移动边缘计算网络研究附Matlab代码.rar
- 基于双层优化的微电网系统规划设计方法附Matlab代码.rar
- 基于一阶剪切变形理论 (FSDT) 的复合材料层压板有限元分析Matlab代码.rar
- 基于小波的锐化特征 (WASH):基于 HVS 的图像质量评估指标Matlab代码.rar
- 基于遗传算法卡车无人机旅行推销员问题Matlab代码.rar
- 基于支持向量机SVM-Adaboost的风电场预测研究附Matlab代码.rar
- 基于蚁群优化算法解决机器人路径规划问题Matlab代码.rar
- 自制数据库迁移工具-C版-05-HappySunshineV1.4-(支持Gbase8a、PG)
- 基于遗传算法求解TSP和MTSP研究Matlab代码实现.rar
- 卡尔曼滤波器、隐式动态反馈、滤波器偏差更新和移动时域估计Matlab代码.rar
- 计及调峰主动性的风光水火储多能系统互补协调优化调度matlab复现.rar
- 考虑阶梯式碳交易机制与电制氢的综合能源系统热电优化附Matlab代码.rar
- 列车-轨道-桥梁交互仿真研究Matlab代码.rar
- 两级三相逆变器的选择性谐波消除PWM(SHEPWM)simulink实现.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈