2012-12-18 8 views
0

저는 MPLAB C18 컴파일러를 사용하여 메모리 게임을 제어하는 ​​PIC18F2550 용 C 코드를 작성하고 있습니다. 사용자는 해당 버튼을 눌러 일련의 깜박이는 LED를 반복합니다. 오래된 시몬 (Simon) 게임과 비슷하지만 순서가 한 번만 발생합니다.PIC18F2550 메모리 게임 PIC C18 프로그래밍 LED 꺼짐

나는 지금까지 어려움을 겪어 왔지만 몇 가지 LED를 켜기 만했지만 버튼은 LED를 1 초간 꺼서 다시 켜 버린다.

여기 내 코드는 지금까지의 :

#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; 
} 

} 

어떤 도움이 크게 감사한다!

+1

실제로 루프하는 프로그램에는 아무 것도 없습니다. 그냥 한 번 실행하고 종료합니다. – JasonD

답변

3

프로그램 실행을 유지하려면 while 루프를 묶어야합니다. 이를 사용하지 않으면 코드가 실행되고 프로그램 카운터가 코드 시작 부분으로 돌아갈 때 칩이 본질적으로 재설정됩니다. 그렇기 때문에 짧은 시간 동안 LED가 꺼지는 것입니다. 왜냐하면 코드가 처음부터 다시 실행되기 시작하여 다시 모두 돌아와야하기 때문입니다.