標(biāo)題: 用面向?qū)ο蟮乃季S開發(fā)STM32__點(diǎn)亮LED [打印本頁]

作者: xiaos    時(shí)間: 2015-4-10 17:24
標(biāo)題: 用面向?qū)ο蟮乃季S開發(fā)STM32__點(diǎn)亮LED
先來定義一個(gè)LED類吧:
class LED_{
public:
    LED_(uint8_t x=1);//構(gòu)造函數(shù)
    void OFF(void);//關(guān)燈函數(shù)
    void ON(void);//開燈函數(shù)
private:
    GPIO_TypeDef    GPIO;//    LED等對應(yīng)的引腳寄存器
    uint16_t GPIO_Pin ;//對應(yīng)寄存器下的引腳
    uint32_t RCC_    ;//對應(yīng)時(shí)鐘
    uint8_t LED_Pin;//保存LED的編號
};

一下是該類的實(shí)現(xiàn):
LED_::LED_(uint8_t x)
{
    LED_Pin=x;
    switch(LED_Pin)
    {
        case 1:{};break;//初始化對應(yīng)的LED的引腳及其時(shí)鐘 以下類似
        case 2:{};break;
        case 3:{};break;
    }
}
void LED_::OFF(void)
{
    switch(LED_Pin)
    {
        case 1://關(guān)閉LED1
        case 2://關(guān)閉LED2
        case 3://關(guān)閉LED3
    }
}

void LED::ON(void)
{
   
  switch(LED_Pin)
    {
        case 1://打開LED1
        case 2://打開LED2
        case 3://打開LED3
    }
}








歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1