728x90

Wednesday, June 9, 2021

PortE programming of dsPIC30F1010 in XC16

PortE of dsPIC30F1010 is a 16-bit bi-directional I/O port. Within the 28-pin SOC package of this device, there are only six usable pins. They are not complex because there are not analog input function relate to this port.

PortE programming of dsPIC30F1010 in XC16

Experiment on breadboard

As it was shown in previous post, total pin numbers and its description is figured out below.

PortE programming of dsPIC30F1010 in XC16

Pin diagram of dsPIC30F1010

In SFR of this controller, PORTE is an input register while LATE is an output register. To get digital input data PORTE register must be read. Writing digital data out, LATE must be modify. TRISE is data direction control register. Writing '1' to this register to make data register as digital input. Clearing this register to make data register as digital output.

PortE programming of dsPIC30F1010 in XC16

dsPIC30F1010/2020 PORT REGISTER MAP

In this programming example I select RE4 as digital input, connecting to a button. RE5 connects an LED as a digital output.

PortE programming of dsPIC30F1010 in XC16

Schematic diagram

This system operates at 5VDC as it's supplied from PICKIT2 device programmer. Internal fast RC oscillator is used in this programming example to cut down component counts during prototyping on breadboard.

Pin 1 connects to reset circuit. Pressing SW1 to restart the system. Whenever SW2 is pressed and released, output LED D1 toggles its logic state.

Device's configuration setting is stored in "config.h" file of project directory.

Click here to download this example in zip file.


Friday, May 28, 2021

Beginning dsPIC30F1010 coding using XC16

Microchip dsPIC30F1010 is a 16-bit micro-controller, targeting for Switch Mode Power Supply (SMPS) Digital Signal Controller (DSC). It comes with many features that I don't show them all here. It has DSP (Digital Signal Processor) engine. It's 10-bit ADC module is able to convert analog signal up to 2Msps. Central Processing Unit (CPU) executes up to 30MIPS.

Start dsPIC30F1010 coding using XC8

dsPIC30F1010 reference image

It has DIP and SMD packages options. DIP package is friendly for breadboard prototyping. I choose a 28-pin SMD package.

Start dsPIC30F1010 coding using XC16

Pin diagrams of dsPIC30F1010

XC16 compiler is a C compiler developed by Microchip Technology. It has a free version that allow the programmer to code without code size limitation. Another C compiler for this 16-bit device is MikroC for dsPIC. However MikroC has code size limitation of 2kB of program space. MikroC has many library functions including peripheral libraries and external device interface libraries. Here I select XC16 v1.32 and MPLABX IDE v1.51. 

To get started I select pin RE5 of Port E to toggle at the rate of 500mS. The device will operate using its internal fast RC oscillator (FRC) with the nominal frequency of 15MHz at +5V DC supply voltage. Main C program shows below.

/*
 * Blinking dsPIC30F1010 using XC16 
 * in MPLABX IDE
 */
#include <p30F1010.h>
#include "config.h"

/*Nominal internal fast oscillator frequency of 15MHz*/
#define FCY 15000000UL
#include <libpic30.h>

void main(void){
    /*Additionaly select the maximum nominal frequency of 15MHz*/
    OSCTUNbits.TUN=0x07;
    /*Clear I/O of PORTE*/
    PORTE=0x0000;
    LATE=0x00000;
    /*PORTE direction as output*/
    TRISE=0x0000;
    while(1){
        /*Toggling RE5*/
        LATEbits.LATE5^=1;
        /*Wait for 0.5 second*/
        __delay_ms(500);
    }
}

It need configuration setting that store in another C header file "config.h" within project directory.

// DSPIC30F1010 Configuration Bit Settings

#include <p30Fxxxx.h>

// FBS
#pragma config BWRP = BWRP_OFF          // Boot Segment Write Protect (Boot Segment may be written)
#pragma config BSS = NO_BOOT_CODE       // Boot Segment Program Flash Code Protection (No Boot Segment)

// FGS
#pragma config GWRP = GWRP_OFF          // General Code Segment Write Protect (General Segment may be written)
#pragma config GSS = GSS_OFF            // General Segment Code Protection (Disabled)

// FOSCSEL
#pragma config FNOSC = FRC              // Oscillator Mode (Internal Fast RC (FRC))

// FOSC
#pragma config POSCMD = PRIOSC_OFF      // Primary Oscillator Source (Primary Oscillator Disabled)
#pragma config OSCIOFNC = OSC2_IO       // OSCI/OSCO Pin Function (OSCO pin has digital I/O function)
#pragma config FRANGE = FRC_HI_RANGE    // Frequency Range Select (High Range)
#pragma config FCKSM = CSW_FSCM_OFF     // Clock Switching and Monitor (Sw Disabled, Mon Disabled)

// FWDT
#pragma config WDTPS = WDTPOST_PS32768  // Watchdog Timer Postscaler (1:32,768)
#pragma config FWPSA0 = WDTPRE_PR128    // WDT Prescaler (1:128)
#pragma config WWDTEN = WINDIS_OFF      // Watchdog Timer Window (Non-Window mode)
#pragma config FWDTEN = FWDTEN_OFF      // Watchdog Timer Enable (Disable)

// FPOR
#pragma config FPWRT = PWRT_128         // POR Timer Value (128ms)

// FICD
#pragma config ICS = ICS_PGD            // Comm Channel Select (Use PGC/EMUC and PGD/EMUD)

// FUID0

// FUID1

Its schematic diagram is shown below.

Start dsPIC30F1010 coding using XC16
Schematic Diagram

Click here to download its zip file.

Start dsPIC30F1010 coding using XC16

XC16 in MPLABX IDE

Start dsPIC30F1010 coding using XC16

Circuit wiring on breadboard

I bought an SMD version of dsPIC30F1010. It was solder on SMD to DIP adapter that will be pinned on breadboard. As we have seen on the figure above, dsPIC30F1010 is placed on breadboard. ICSP adapter of PICKIT 2 connects to this microcontroller for in system programming and powering via USB bus. The controller operates at +5V from USB bus. It does not require an external crystal oscillator, as its internal fast RC oscillator is used.

 


Saturday, May 22, 2021

ATMega32 LCD and Keypad Interfacing Example

In previous example I showed a simple keypad programming example using C in Atmel Studio 7. It displays key value on a typical single seven segments display. We can add a character LCD as an output device.

In this programming example we use a 4x4 keypad matrix as a digital input, and a character LCD bases on HD44780 as an output device. A 20x4 character LCD is used to show information a key value.

ATMega32 LCD and Keypad Interfacing Example
Program starts up

Port C is 8-bit wide, connects to a 4x4 matrix keypad as shown in the picture above. Port D connects to a character LCD in 8-bit mode. Read/Write pin is ignored, and it's connects to ground as the LCD just accept the data/command from micro-controller.

Atmega32 operates at 16MHz supplies at +5V DC supply voltage.

C main program shows below. It requires LCD and Keypad driver files that I don't show them here.

/*
 * m32LcdKeyPad.c
 *
 * Created: 5/18/2021 10:15:15 PM
 * Author : aki-technical
 */ 

#include <avr/io.h>

#define F_CPU 16000000UL
#include <util/delay.h>

#include "keypad4x4.h"
#include "m32Lcd.h"

void writeTitle(void);

unsigned char getKey=0;

int main(void)
{
unsigned char pressCount=0,newLine=0,lineCount=1;
DDRD=0xFF;
PORTD=0x00;
keyInit();
lcdInit();
setXy(0,0);
writeString("Atmega32 LCD KeyPad");
setXy(0,1);
writeString("Interfacing Example");
setXy(0,2);
writeString("Programing in C ");
setXy(0,3);
writeString("in Atmel Studio 7");
_delay_ms(2500);
writeTitle();
while(1)
{
getKey=scan();
if (getKey!=0)
{
writeChararacter(getKey);
_delay_ms(250);
pressCount+=1;
getKey=0;
}
if (pressCount==20)
{
newLine=1;
lineCount++;
pressCount=0;
}
if (newLine)
newLine=0;
setXy(0,lineCount);
}
if (lineCount==4)
{
lineCount=1;
writeTitle();
}
}
}

void writeTitle(void){
/*Clear LCD*/
writeCommand(LCD_CLEAR);
setXy(0,0);
writeString("Enter Key Value: ");
writeCommand(CURSOR_ON);
setXy(0,1);
}

Click here to download this example in zip file. I additionally add its schematic diagram below.

ATMega32 LCD and Keypad Interfacing Example
Schematic

If you want a standard PCB for ATMega32 micro-controller, you can order my AVR Microcontroller project from PCBWay with a reasonable price. Click here to get a free $5 credit for new account.


See Also,

Search This Blog