uart2_timer2_tx.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2021 IOsetting <iosetting(at)outlook.com>
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /***
  15. * Demo: UART2 TX
  16. *
  17. * Pin connection:
  18. * STC8G/STC8H USB2TTL
  19. * P10 -> TX
  20. * P11 -> RX
  21. */
  22. #include "fw_hal.h"
  23. void main(void)
  24. {
  25. SYS_SetClock();
  26. // P10:RX, P11:TX
  27. UART2_SwitchPort(UART2_AlterPort_P10_P11);
  28. // GPIO Config
  29. GPIO_P1_SetMode(GPIO_Pin_0|GPIO_Pin_1, GPIO_Mode_InOut_QBD);
  30. // UART2, baud 115200, baud source Timer2, 1T mode, no interrupt
  31. UART2_Set8bitUART();
  32. UART2_Config(HAL_State_ON, 115200);
  33. while(1)
  34. {
  35. UART2_TxChar('T');
  36. UART2_TxHex(0x41);
  37. UART2_TxString("U");
  38. UART2_TxString(" string\r\n");
  39. SYS_Delay(1000);
  40. }
  41. }