|
|
【注】德州儀器的官網上的msp430fr6989單片機上有一塊lcd,其有40個引腳,分別兩邊各有20個引腳排布。學過stm32的能很快掌握lcd的寄存器模式下寫成的代碼,但是新手最好入門庫函數一類,如果時間很緊迫的情況下。板上是0-7的行,分為上半屏和下半屏。列有LCDM1-LCDM20,總共有8*20=160個segment。在前面的帖子中,對引腳的定義是通過寄存器進行定義的,而如果我要讓流水燈亮起來就可以把寄存器及地址寫在一個函數內,包裝起來,直接在官網上找的代碼,很豐富,學這個很快。比如以下:
- <p>//定義輸出引腳
- void GPIO_setAsOutputPin(uint8_t selectedPort,
- uint16_t selectedPins) {
- uint16_t baseAddress = GPIO_PORT_TO_BASE[selectedPort];</p><p> #ifndef NDEBUG
- if(baseAddress == 0xFFFF)
- {
- return;
- }
- #endif</p><p> // Shift by 8 if port is even (upper 8-bits)
- if((selectedPort & 1) ^ 1)
- {
- selectedPins <<= 8;
- }</p><p> HWREG16(baseAddress + OFS_PASEL0) &= ~selectedPins;
- HWREG16(baseAddress + OFS_PASEL1) &= ~selectedPins;
- HWREG16(baseAddress + OFS_PADIR) |= selectedPins;</p><p> return;
- }</p><p>
- </p><p>
- </p><p>Init_GPIO();
-
- GPIO_clearInterrupt(GPIO_PORT_P1, GPIO_PIN1);
- GPIO_clearInterrupt(GPIO_PORT_P1, GPIO_PIN2);</p><font size="5"><p>void Init_GPIO(void)
- {
- // Set all GPIO pins to output low to prevent floating input and reduce power consumption
- GPIO_setOutputLowOnPin(GPIO_PORT_P1, GPIO_PIN0|GPIO_PIN1|GPIO_PIN2|GPIO_PIN3|GPIO_PIN4|GPIO_PIN5|GPIO_PIN6|GPIO_PIN7);
- GPIO_setOutputLowOnPin(GPIO_PORT_P2, GPIO_PIN0|GPIO_PIN1|GPIO_PIN2|GPIO_PIN3|GPIO_PIN4|GPIO_PIN5|GPIO_PIN6|GPIO_PIN7);
- GPIO_setOutputLowOnPin(GPIO_PORT_P3, GPIO_PIN0|GPIO_PIN1|GPIO_PIN2|GPIO_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O_PIN7);
- GPIO_setAsOutputPin(GPIO_PORT_P4, GPIO_PIN0|GPIO_PIN1|GPIO_PIN2|GPIO_PIN3|GPIO_PIN4|GPIO_PIN5|GPIO_PIN6|GPIO_PIN7);
- GPIO_setAsOutputPin(GPIO_PORT_P5, GPIO_PIN0|GPIO_PIN1|GPIO_PIN2|GPIO_PIN3|GPIO_PIN4|GPIO_PIN5|GPIO_PIN6|GPIO_PIN7);
- GPIO_setAsOutputPin(GPIO_PORT_P6, GPIO_PIN0|GPIO_PIN1|GPIO_PIN2|GPIO_PIN3|GPIO_PIN4|GPIO_PIN5|GPIO_PIN6|GPIO_PIN7);
- GPIO_setAsOutputPin(GPIO_PORT_P7, GPIO_PIN0|GPIO_PIN1|GPIO_PIN2|GPIO_PIN3|GPIO_PIN4|GPIO_PIN5|GPIO_PIN6|GPIO_PIN7);
- GPIO_setAsOutputPin(GPIO_PORT_P8, GPIO_PIN0|GPIO_PIN1|GPIO_PIN2|GPIO_PIN3|GPIO_PIN4|GPIO_PIN5|GPIO_PIN6|GPIO_PIN7);
- GPIO_setAsOutputPin(GPIO_PORT_P9, GPIO_PIN0|GPIO_PIN1|GPIO_PIN2|GPIO_PIN3|GPIO_PIN4|GPIO_PIN5|GPIO_PIN6|GPIO_PIN7);
-
- GPIO_setAsInputPin(GPIO_PORT_P3, GPIO_PIN5);
-
- // Configure button S1 (P1.1) interrupt
- GPIO_selectInterruptEdge(GPIO_PORT_P1, GPIO_PIN1, GPIO_HIGH_TO_LOW_TRANSITION);
- GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN1);
- GPIO_clearInterrupt(GPIO_PORT_P1, GPIO_PIN1);
- GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN1);
-
- // Configure button S2 (P1.2) interrupt
- GPIO_selectInterruptEdge(GPIO_PORT_P1, GPIO_PIN2, GPIO_HIGH_TO_LOW_TRANSITION);
- GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P1, GPIO_PIN2);
- GPIO_clearInterrupt(GPIO_PORT_P1, GPIO_PIN2);
- GPIO_enableInterrupt(GPIO_PORT_P1, GPIO_PIN2);
-
- // Set P4.1 and P4.2 as Secondary Module Function Input, LFXT.
- GPIO_setAsPeripheralModuleFunctionInputPin(
- GPIO_PORT_PJ,
- GPIO_PIN4 + GPIO_PIN5,
- GPIO_PRIMARY_MODULE_FUNCTION
- );
-
- // Disable the GPIO power-on default high-impedance mode
- // to activate previously configured port settings
- PMM_unlockLPM5();</p><p>}</p></font><p>
- </p>
復制代碼 下面有開箱的源代碼。【禁止商業用途】
|
評分
-
查看全部評分
|