簡體   English   中英

使用 PIC18 的隨機骰子項目

[英]Random Dice Project using PIC18

我正在使用 PIC18 CPU 開發隨機數生成器。

如果按下按鈕並且我的仿真器顯示錯誤消息,則數字不會顯示:“[PIC18] PC=0x0000。$MCLR$ 低。處理器處於重置狀態。[U1]”在 Proteus 中。

這是我的代碼:

#pragma config MCLRE=OFF

sbit   DIS1   at PORTD.B6;     //Define Display 1 at Port D pin RD 6
sbit   DIS2   at PORTD.B7;     //Define Display 2 at Port D pin RD


unsigned char Code[10]={0x40, 0x79, 0x24, 0x30, 0x19, 0x12, 0x02, 0x78, 0x00, 0x10};
unsigned char DEC, DIG, DEL; //Define variable
void MSDelay (unsigned char Time) //Delay
{
   unsigned char y,z; //Define variable
   for (y=0; y<Time; y++) //For loop for Delay
   for (z=0; z<254; z++); //For loop for Delay
}

void main () //Main Function
{
  TRISC = 0;//Define PORTC as Output Port
  TRISD.RD6 = 0; //Define RD6 as Output Pin
  TRISD.RD7 = 0; //Define RD7 as Output Pin
  DIS1= 0;//Turn OFF Display 1
  DIS2= 0; //Turn OFF Display
  while (1) //End-Less Loop
{
for (DEC=0; DEC<10;DEC++)
{
    for (DIG=0; DIG<10; DIG++) //For Loop for Display Digit Number
    {
        for (DEL=0; DEL<10; DEL++) //Delay for next digit
        {
                DIS1 = 1; //Turn ON Display 1
                PORTC = Code [DEC]; //Find code and send to the PORTC
                MSDelay(10) ; //Delay for Turning ON the display
                DIS1 = 0; //Turn OFF Display I
                DIS2 = 1; //Turn ON Display
                PORTC= Code [DIG]; //Find code and send to the PORTC
                MSDelay (10) ; //Delay for Turning ON the display
                DIS2 = 0;//Turn OFF Display 2
                }
    }
}
}
}

我的設置的示意圖可以在這里看到

問題是什么?

[PIC18] PC=0x0000。 $MCLR$ 低。 處理器處於復位狀態。 [U1]

 #pragma config MCLRE=OFF

並非所有模擬器都支持微控制器配置( #pragma config )。

我什至在 Microchip 網站上發現了一個論壇條目,這可能不適用於真正的微控制器!

“$MCLR$ 低。處理器處於復位狀態。” 意味着您的模擬器不關心#pragma config MCLRE=OFF行。

你有很多未使用的引腳。 我會使用不同的引腳(例如 RE0 而不是 RE3)。

就個人而言,除非確實有必要,否則我也不會更改真實微控制器( #pragma config )的 controller 配置:

如果出現問題,您可能會使微控制器變磚,並且無法再使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM