[問題] 籃球記分板 宣告變數跑不出來
我要用PXA270 透過鍵盤 用終端機 把分數顯示出來
分成2隊 1~8個按鍵 分別+1分~+3分 -1分
個別設變數 在全域變數 總分設sum、sum1
int sum=0,sum1=0;
int a=1,b=2,c=3,d=-1;
但是執行時 變數都是亂數 怪怪的
不知可不可以用for迴圈寫 每個按鍵加分功能
如果可以 +1分~+3分程式 要放在哪裡
這是我的程式碼 ↓↓↓↓
#include "register_variant.h"
#define LED_CS2 (*((volatile unsigned short *)(0x10300000)))
#define KEY_VALUE (*(volatile unsigned char*)(switch_dummyAddress))
#define LAST_KEY_VAL (*(volatile unsigned char *)(buttonStatus))
#define LAST_LED_VAL (*(volatile unsigned char *)(ledStatusBuffer))
#define REG_ICPR (*(volatile unsigned long *)(int_ICPR))
#define REG_RTSR (*(volatile unsigned long *)(rtc_RTSR))
#define RCNR (*(volatile unsigned long *)(0x40900000))
#define RTAR (*(volatile unsigned long *)(0x40900004))
#define RTSR (*(volatile unsigned long *)(0x40900008))
#define RTTR (*(volatile unsigned long *)(0x4090000C))
#define RDCR (*(volatile unsigned long *)(0x40900010))
#define RYCR (*(volatile unsigned long *)(0x40900014))
#define RDAR1 (*(volatile unsigned long *)(0x40900018))
#define RYAR1 (*(volatile unsigned long *)(0x4090001C))
#define RDAR2 (*(volatile unsigned long *)(0x40900020))
#define RYAR2 (*(volatile unsigned long *)(0x40900024))
#define SWCR (*(volatile unsigned long *)(0x40900028))
#define SWAR1 (*(volatile unsigned long *)(0x4090002C))
#define SWAR2 (*(volatile unsigned long *)(0x40900030))
#define RTCPICR (*(volatile unsigned long *)(0x40900034))
#define PIAR (*(volatile unsigned long *)(0x40900038))
extern void SerialInit(void);
extern void SerialOutputByte(const char );
extern void SerialOutputString(char *);
extern int SerialInputByte(char *);
unsigned long year;
unsigned long month;
unsigned long day;
unsigned long hour;
unsigned long minute;
unsigned long second;
int sum=0,sum1=0;
int a=1,b=2,c=3,d=-1;
void Init_RTC(void)
{
RTSR = 0x0; //reset the status registers
RCNR = 0x0; //reset the clock counter
RYCR = 0xfae21; //set the data 2007.1.1
RDCR = 0x1e0000; //set the time 00:00:00
}
void Display(void)
{
year = (RYCR << 11) >> 20; //(RYCR >> 9 ) && 0xfff;
month = (RYCR << 23) >> 28;
day = (RYCR << 27) >> 27;
hour = (RDCR << 15) >> 27;
minute = (RDCR << 20) >> 26;
second = (RDCR << 26) >> 26;
//POST_SerialPrintf("2_RDCR = %x, 2_RYCR = %x",RDCR,RYCR);
POST_SerialPrintf("The Current Date is:%4d,%2d,%2d",year,month,day);
//POST_SerialPrintf("The date
is:%4d,%2d,%2d",year_reg->ye,year_reg->mon,year_reg->dom);
POST_SerialPrintf("The Current Time is:%2d:%2d:%2d",hour,minute,second);
}
void options(void)
{
POST_SerialPrintf("********************************");
POST_SerialPrintf(" A B ");
POST_SerialPrintf(" ");
POST_SerialPrintf(" ");
POST_SerialPrintf("%2d",sum);
POST_SerialPrintf(" ");
POST_SerialPrintf("%2d",sum1);
POST_SerialPrintf(" ");
POST_SerialPrintf("*********************************");
//SerialOutputString("Your Choice is:");
//POST_SerialPrintf("\r\n");
}
void dummyOs()
{
char cc;
XsFFUartSWInit();
options();
Init_RTC();
while (1)
{
if (SerialInputByte(&cc))
{
if (cc == 49)
{
SerialOutputByte(cc);
Display();
POST_SerialPrintf("\n");
options();
}
if (cc == 50)
{
SerialOutputByte(cc);
Display();
POST_SerialPrintf("\n");
options();
}
if (cc == 51)
{
SerialOutputByte(cc);
Display();
POST_SerialPrintf("\n");
options();
}
if (cc == 52)
{
SerialOutputByte(cc);
Display();
POST_SerialPrintf("\n");
options();
}
if (cc == 53)
{
SerialOutputByte(cc);
Display();
POST_SerialPrintf("\n");
options();
}
if (cc == 54)
{
SerialOutputByte(cc);
Display();
POST_SerialPrintf("\n");
options();
}
if (cc == 55)
{
SerialOutputByte(cc);
Display();
POST_SerialPrintf("\n");
options();
}
if (cc == 56)
{
SerialOutputByte(cc);
Display();
POST_SerialPrintf("\n");
options();
}
}
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.117.169.102
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章