- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 MPLAB C18 编译器为用于控制内存游戏的 PIC18F2550 编写 C 代码。用户通过按下相应的按钮来重复一系列闪烁的 LED。有点像老式的西蒙游戏,但一个序列只发生一次。
到目前为止,我一直在努力,我只设法让一些 LED 灯亮起,但按钮只会让 LED 灯熄灭一秒钟,然后它们会再次亮起。
到目前为止,这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <p18f2550.h>
#include <delays.h>
//#pragma config WDT = OFF //Disable watchdog timer
// LED Configuration
#define LED_PIN_0 LATAbits.LATA0 //RA0
#define LED_PIN_1 LATAbits.LATA1 //RA1
#define LED_PIN_2 LATAbits.LATA2 //RA2
#define LED_PIN_3 LATAbits.LATA3 //RA3
#define LED_PIN_4 LATAbits.LATA4 //RA4
#define LED_PIN_5 LATAbits.LATA5 //RA5
#define LED_PIN_6 LATAbits.LATA6 //RA6
// Push Button Configuration
#define PUSH_BUTTON_0 PORTBbits.RB0 //RB0
#define PUSH_BUTTON_1 PORTBbits.RB1 //RB1
#define PUSH_BUTTON_2 PORTBbits.RB2 //RB2
#define PUSH_BUTTON_3 PORTBbits.RB3 //RB3
#define PUSH_BUTTON_4 PORTBbits.RB4 //RB4
#define PUSH_BUTTON_5 PORTBbits.RB5 //RB5
#define PUSH_BUTTON_6 PORTBbits.RB6 //RB6
// Global Variables
int led_array[7] ; // array storing the pin outs
int button_array[7] ;
void main()
{
int i;
ADCON1 = 0b11111111;
TRISA = 0; // sets the LED pins to output
TRISB = 1; // sets pushbutton pins to input
PORTA = 0;
PORTB = 0;
//sequence
led_array[0] = 1 ;
led_array[1] = 0 ;
led_array[2] = 1 ;
led_array[3] = 0 ;
led_array[4] = 1 ;
led_array[5] = 1 ;
led_array[6] = 0 ;
// Configure the LEDs
LED_PIN_0 = led_array[0] ;
LED_PIN_1 = led_array[1] ;
LED_PIN_2 = led_array[2] ;
LED_PIN_3 = led_array[3] ;
LED_PIN_4 = led_array[4] ;
LED_PIN_5 = led_array[5] ;
LED_PIN_6 = led_array[6] ;
// Configure the push button array
PUSH_BUTTON_0 = button_array[0] ;
PUSH_BUTTON_1 = button_array[1] ;
PUSH_BUTTON_2 = button_array[2] ;
PUSH_BUTTON_3 = button_array[3] ;
PUSH_BUTTON_4 = button_array[4] ;
PUSH_BUTTON_5 = button_array[5] ;
PUSH_BUTTON_6 = button_array[6] ;
if ( PUSH_BUTTON_0 == 1 )
{
led_array[0] = 0;
}
if ( PUSH_BUTTON_1 == 1 )
{
led_array[1] = 1;
}
if ( PUSH_BUTTON_2 == 1 )
{
led_array[2] = 0;
}
if ( PUSH_BUTTON_3 == 1 )
{
led_array[3] = 1;
}
if ( PUSH_BUTTON_4 == 1 )
{
led_array[4] = 0;
}
if ( PUSH_BUTTON_5 == 1 )
{
led_array[5] = 0;
}
if ( PUSH_BUTTON_6 == 1 )
{
led_array[6] = 1;
}
}
非常感谢任何帮助!!
最佳答案
您需要一个封闭的 while 循环来保持程序的执行。没有它,您的代码将执行,并且当程序计数器返回到代码的开头时,芯片将基本上重置。这就是为什么您的 LED 会短暂关闭的原因,因为您的代码会再次从头开始执行,所有 LED 都会重新打开。
关于c - PIC18F2550内存游戏PIC C18编程LED灭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13934096/
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 6年前关闭。 Improve thi
让我们快速回顾一下以下案例: 不将动态链接与位置无关代码相结合。我可能敢说这是一个不可能的案例,但当我深入探讨这个主题时,我不太确定。 将静态链接与位置无关代码相结合。我相信这作为一个有效的组合是完全
我正在将一个线程局部变量添加到几个始终直接链接到可执行文件的目标文件中。这些对象永远不会包含在共享库中(并且可以安全地假设这在可预见的 future 会成立)。这意味着这些对象不需要 -fPIcfla
这个问题与this one有关以及它的答案。 我刚刚在我正在处理的构建中发现了一些丑陋之处。情况看起来有点像下面(用gmake格式写的);请注意,这特别适用于 sparc 和 x86 硬件上的 32
我在 PIC 的 mikroC 中实现基于定时器的中断时遇到问题。 如果 PORTC.F0 处有按键,我想切换端口引脚 8 次,并且切换之间应该有 100 毫秒的延迟。 通常使用延迟函数这会很容易 f
我试图通过 SPI 通信让 PIC1 成为主机,PIC2 成为从机。我想从 PIC1(master)发送命令到 PIC2(slave),然后让它做一些事情。但是,我也想通过 SPI 通信建立从 PIC
我正在使用 cvSplit() 来分离 RGB channel 并将它们打印在 3 个不同的图像中,显示颜色 r、g 和 b。但我只有黑白照片的 BW 图像。这是使用 cvSplit() 时的正确输出
初始化以下变量时: 01 BATCH-REC. 03 BATCH-VERSION PIC X(2). 03 BATCH-FIELDS
当我在学习 javafx 教程并尝试为 ImageView 创建一个新的 Image 实例以将其用于 TreeView 时,我注意到导师曾经创建一个 ImageView:new ImageView(n
我正在研究 PIC16F887,我的任务主要基于 adc 读数(8 位)。有 10 个不同的模拟输入,因此逐个读取它们需要相当长的时间。时钟为 20Mhz,adc 唯一允许的设备频率为 Fosc/32
我有一 block 带有特殊 UEXT connector 的 Olimex A20 板它可以连接 SPI、I2C 和 RS 232。我喜欢使用 Olimex 的 MOD Zigbee 模块直接通过
有没有办法在不使用pickit型编程器的情况下编程(闪存)裸(尚未使用引导加载程序闪存)pic32芯片? 例如,是否有任何正在进行的 JTAG 项目? 最佳答案 建议您引用Microchip PIC3
阅读时this blogpost , 当作者试图证明共享库需要 PIC 时,我遇到了以下情况。 If your shared library is built to only work when lo
我是 PIC mcu 的新手。我使用 pic12f675 MPLAB 和 XC8 来制作 LED 多次闪烁模式。 我有按钮问题(经过审查,它调用了 Bounce 和 Debounce)。 有时当我按下
是否有用于不可屏蔽中断的独立通信总线绕过可编程中断 Controller ? 或者 PIC 是否管理所有中断,但按照约定传递所有不可屏蔽中断? 这是否取决于架构,或者是否有特定的理由选择其中一种而不是
我想问一下如何在PIC C编译器中为PIC18f4620编写代码,以便在模拟输入之一为1时传输日期 最佳答案 对于这个网站来说,这个问题实在是太宽泛了。如何编写代码取决于您使用的 PIC C 编译
我是 PIC 编程新手,正在使用 MPLAb。我有一个关于中断的问题..所以我想做的是,当我按下按钮时,我想打开 LED 0,如果我松开按钮,则打开 LED 1。我认为我编写的代码有意义,但它不起作用
我想用我的PIC18F4550、蓝牙模块HC-06和电脑做一个简单的测试。我的意思是,我想使用蓝牙模块将一个简单的字符从 PIC 发送到 PC。 它应该在终端中出现一个“A”,但出现的是十六进制的 F
所以我使用的微型芯片是 PIC 18F。 如果设置了Alarm_Status.bits.b3(本质上只是一个开关),则会创建警报。第一个代码片段按其应有的方式工作 BS(TRISB,7);
经过大量的试错和堆砌,我(我们)设法让两张图片以一种非常特殊的方式重叠: 这是这样实现的: .container { width: 900px; margin: auto; } .center
我是一名优秀的程序员,十分优秀!