Menu

Adskeeper - header widge

728x90

Search This Blog

468x60

Navbar

AdsKeeper - IAB Display Standard Ad Unit

Saturday, October 10, 2026

dsPIC30F2010 MikroC for dsPIC UART Example

Overview

The UART is a simple serial communication interface exists in most of micro-controllers. Its protocol is very simple. A build-in UART module of a micro-controller offer a high speed, configurable and reliable data communication. This module doesn't exist in some low-end 8-bit micro-controller for example the PIC16F54 or the popular PIC16F84A. However the programmer can emulate this communication protocol in firmware such Assembly or even embedded C programming language (Software UART) due to its clarity. Some C compilers have their software UART allowing the user access to their build-in function libraries.

 

dsPIC30F2010 MikroC for dsPIC UART Example
UART Received ASCII Data

 

This communication interface is used to interact between micro-controller to microcontroller due to its two data wire - Transmit (TX) and Receive (RX). Some peripheral device such as GSM module, Wi-Fi modem (ESP8266), or HMI use UART.

 

MikroC for dsPIC UART Library

MikroC has built-in UART library that supports both hardware and software UART. Hardware UART implements the internal dedicated UART modules of any 16-bit PIC micro-controllers. Some 16-bit PIC micro-controllers have more than one UART interface, UART1, UART2, etc.

These are MikroC Hardware UART Library Routines:

Library Routines

Generic Routines

 

Now let test the UART1 communication interface of the dsPIC30F2010 using the MikroC UART example.

MikroC Source Code:



  1. char uart_rd;

  2. void main() {

  3. UART1_Init(9600); // Initialize UART module at 9600 bps
  4. Delay_ms(100); // Wait for UART module to stabilize

  5. // U1MODEbits.ALTIO = 1; // Un-comment this line to have Rx and Tx pins on their alternate
  6. // locations. This is used to free the pins for other module, namely the SPI.

  7. UART1_Write_Text("Start");
  8. UART1_Write(10);
  9. UART1_Write(13);

  10. while (1) { // Endless loop
  11. if (UART1_Data_Ready()) { // If data is received,
  12. uart_rd = UART1_Read(); // read the received data,
  13. UART1_Write(uart_rd); // and send data via UART
  14. }
  15. }
  16. }

 

In the Library Manger Window, Tick on UART. Then build the source code.

 

dsPIC30F2010 MikroC for dsPIC UART Example
UART in Library Manager

 

In MikroC IDE, go to Tools -> USART Terminal to open the interface.

 

dsPIC30F2010 MikroC for dsPIC UART Example
USART Terminal

 

Enter any characters and click Send, then the MCU will send back the received data. UART requires a precise micro-controller timing. So don't forget to set a correct clock source and frequency.

Let put a character LCD that displays received ASCII characters from PC Serial Port Terminal.

MikroC Source Code:

  1. // LCD module connections
  2. sbit LCD_RS at LATE0_bit;
  3. sbit LCD_EN at LATE1_bit;
  4. sbit LCD_D4 at LATE2_bit;
  5. sbit LCD_D5 at LATE3_bit;
  6. sbit LCD_D6 at LATE4_bit;
  7. sbit LCD_D7 at LATE5_bit;

  8. sbit LCD_RS_Direction at TRISE0_bit;
  9. sbit LCD_EN_Direction at TRISE1_bit;
  10. sbit LCD_D4_Direction at TRISE2_bit;
  11. sbit LCD_D5_Direction at TRISE3_bit;
  12. sbit LCD_D6_Direction at TRISE4_bit;
  13. sbit LCD_D7_Direction at TRISE5_bit;
  14. // End LCD module connections

  15. char txt1[] = "dsPIC30F2010";
  16. char txt2[] = "UART Example";
  17. char txt3[] = "Lcd4bit";
  18. char txt4[] = "example";

  19. char i=1;
  20. char uart_rd;

  21. void main(){
  22. ADPCFG = 0xFFFF; // Configure AN pins as digital I/O

  23. Lcd_Init(); // Initialize LCD
  24. UART1_Init(9600); // Initialize UART module at 9600 bps
  25. Delay_ms(100); // Wait for UART module to stabilize
  26. UART1_Write_Text("Reply for dsPIC30F2010 MCU");
  27. UART1_Write(10);
  28. UART1_Write(13);
  29. Lcd_Cmd(_LCD_CLEAR); // Clear display
  30. Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
  31. Lcd_Out(1,3,txt1); // Write text in first row

  32. Lcd_Out(2,3,txt2); // Write text in second row
  33. Delay_ms(5000);

  34. Lcd_Cmd(_LCD_CLEAR); // Clear display
  35. Delay_ms(10);
  36. Lcd_Out(1, 1 ,"PC Terminal:");

  37. while(1) { // Endless loop
  38. if (UART1_Data_Ready()) { // If data is received,
  39. uart_rd = UART1_Read(); // read the received data,
  40. UART1_Write(uart_rd); // and send data via UART
  41. Lcd_Chr(2, i, uart_rd);
  42. i++;
  43. }
  44. if(i>15) {
  45. i = 1;
  46. Lcd_Cmd(_LCD_CLEAR);
  47. Delay_ms(10);
  48. Lcd_Out(1 ,1 ,"PC Terminal:");
  49. }
  50. }
  51. }

 

The LCD shows UART characters, and the MCU will clears it automatically whenever the UART receiving counts reach 15.

Schematic:


dsPIC30F2010 MikroC for dsPIC UART Example
Schematic Diagram in Proteus


dsPIC30F2010 Prototype Board Testing:

 

dsPIC30F2010 MikroC for dsPIC UART Example
Serial Port Terminal

 

dsPIC30F2010 MikroC for dsPIC UART Example
Testing Program

 
dsPIC30F2010 MikroC for dsPIC UART Example
UART ASCII Data Receiving

 

 

 

 

No comments:

Post a Comment

Adskeep- Standard Ads

336x280

DIY Electronic Projects And Instruments

AdsKeeper - 2091654

Labels

23K256 (1) 24C16B (2) 25AA010A (2) 8051 (7) 93AA46B (1) ADC (36) Analog Comparator (1) Arduino (16) ARM (32) AT89C52 (7) ATMega32 (59) ATMega644P (27) AVR (88) AVR PCB (2) Bootloader (1) CCS PICC (31) Change Notify Interrupt (CNI) (2) DAC (2) DHT11 (5) Display (152) Distance Sensor (3) dot matrix (1) ds1307 (10) DS18B20 (6) ds3231 (1) ds3232 (2) dsPIC (8) dsPIC30F1010 (3) dsPIC30F2010 (9) EEPROM (5) Environment Sensor (6) ESP32 (1) esp8266 (1) Graphical LCD (3) HD44780 (8) I2C (38) ILI9341 (1) Input/Output (82) Interrupt (22) IoT PCB (1) Keil (5) Keypad (16) KS0108 (3) LCD (82) LM35 (4) Master/Slave (2) MAX7221 (1) MCP23017 (8) MCP23S17 (7) MCP4921 (1) MCP4922 (2) Meter (3) MikroC (2) MikroC ARM (1) MikroC dsPIC (3) Module PCB (2) Motor (15) MPLABX (73) Nokia 5110 LCD (4) OLED (2) One-Wire (7) Oscillator (8) PCB (13) PCD8544 (3) PCF8574 (10) PIC (112) PIC12F (3) PIC16 (105) PIC16F628A (3) PIC16F630 (2) PIC16F716 (4) PIC16F818 (11) PIC16F818/819 (3) PIC16F84A (16) PIC16F876A (2) PIC16F877A (9) PIC16F88 (2) PIC16F887 (60) PIC18 (19) PIC18F1220 (5) PIC18F2550 (5) PIC18F4550 (12) PICKit2 (1) PICMicro PCB (4) Pin Change Interrupt (1) PWM (12) RTC (12) SBN0064G (1) Sensor (15) SH1106 (3) Shift Register (14) Shift Registers (16) SN74HC595N (4) Software TWI (2) SPI (41) ST7735 (1) STM32 (29) STM32 Black Pill (1) STM32 Blue Pill (12) STM32 HAL (23) STM32CubeIDE (32) STM32F103C8T6 (9) STM32F103R6 (18) STM32F401CCU6 (1) SysTick (7) temperature sensor (15) TFT (1) TG12864A (1) Thermometer (22) Timer/Counter (32) TM1637 (2) twi (10) UART (11) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (96)