Quantcast
Channel: LED Projects - PIC Microcontroller
Viewing all 387 articles
Browse latest View live

RGB LED SHOW PIC12F675

$
0
0

Hello Electronic lovers that I have done it again with you in this article is an applications often wanted to share. In this study, using the PIC12F675 and 74HC595 Entegere be moved sequential RGB… Electronics Projects, RGB led show PIC12F675 “led projects, microchip projects, microcontroller projects, simple circuit projects, “

RGB LED

Hello Electronic lovers that I have done it again with you in this article is an applications often wanted to share. In this study, using the PIC12F675 and 74HC595 Entegere be moved sequential RGB light with a very nice splash of color emerges.

Isis video of the application circuit and the hex code is available in the attached document. Friends who are interested let you go.

PICMICRO CONNECTION EXAMPLE 74HC595

 

PICMICRO CONNECTION EXAMPLE 74HC595

Source: RGB LED SHOW PIC12F675 RGB led show PIC12F675 proteus isis simulation, pcband source code files: RGB led show PIC12F675 .ZIP

The post RGB LED SHOW PIC12F675 appeared first on PIC Microcontroller.


PIC16F877 16X16 LED MATRIX 74HC595 GRAPHIC DISPLAY PROJECT

$
0
0

Hello Electronics lovers. After a long hiatus, I wanted to write something again. In this article, software-serial basis (soft SPI) and still other applications I wrote using the name for a project I would... Electronics Projects, PIC16F877 16X16 LED Matrix 74HC595 Graphic Display Project “microchip projects, microcontroller projects, pic16f877 projects, “

GRAPHIC DISPLAY PROJECT

 

Hello Electronics lovers. After a long hiatus, I wanted to write something again. In this article, software-serial basis (soft SPI) and still other applications I wrote using the name for a project I would like to help. 16 × 16 matrix graphic display I share with you my work on the foundations of

I compiled using pic16F877 74HC595 recorder at a speed of 20Mhz with these applications through screening method to create visual graphics display basic circuit diagram of the ISIS software mikroC C and Hex code attached file is available.

We also aim to have you with visual examples to work in 24 × 24 graphic display

PROTEUS ISIS CIRCUIT 16X16 LED MATRIX SCHEMATIC

PROTEUS ISIS CIRCUIT 16X16 LED

PROTEUS ISIS CIRCUIT 16X16 LED (1)
PROTEUS ISIS CIRCUIT 16X16 LED

Source: PIC16F877 16X16 LED MATRIX 74HC595 GRAPHIC DISPLAY PROJECT Proteus isis led applications and the Matrix code files: pic16f877-16×16-matrix-74hc595-graphic-display-project.zip

The post PIC16F877 16X16 LED MATRIX 74HC595 GRAPHIC DISPLAY PROJECT appeared first on PIC Microcontroller.

Push Button as Input and Led as Output with Pic Microcontroller

$
0
0

This is a simple tutorial/project on how to interface a transistor (2n2222), led and push button with Pic microcontroller. In the project i am going to switch on and off(blink) an led with the help of a push button. Since transistors are used at outputs we can drive heavy loads with the same circuit. Pic16f877 microcontroller is used in the project. Port-B of Pic16f877 is used as output port. Port-B of pic16f877 is an 8-bit port. 8 transistors are connected to the general purpose input/output pins (gpio’s) of this port. Transistors bases are connected directly to the pins of port-b. Led’s are connected to emitter side of transistor in series to a 560 ohm resistor. Collector side of each transistor is supplied an external 5 volt signal.
An external 20 Mhz crystal is used to supply clock to microcontroller. Crystal is attached to microcontroller in parallel to two 33 pf capacitors. Push button is attached to Port-D Pin#7. 1 K ohm resistor is attached in series to a push button, other leg of push button is attached to +5v signal. 

Push Button as Input and Led as Output with Pic Microcontroller

Code is written using MPLAB-IDE and High Tech C compiler is used to compile code and generate Intel hex file of the code. First the necessary header file htc.h is included in the code. This header file is necessary to be included in every code that is written in MPLAB-IDE and uses High Tech C compiler to compile the code. If you didn’t include this header file in your code the htc(high tech c compiler) compiler will be unable to recognize the code. This header file tells the htc compiler that this is his code and he has to compile it. 

_XTAL_FREQ 20e6 statement is specifying the crystal frequency that is attached to the microcontroller. I am Using 20 Mhz external crystal with the controller so i specified 20e6(Equivalent to 20e6=20,000,000).

Statement #define Input RD7 is defining Port-D Pin#7 as Input. Now we can access Port-D Pin#7 with the name ‘Input’. TRISB=0x00; Statement is declaring Port-B as Output. TRISD=0x80; Statement is declaring Port-D Pin#7 as Input. (0x80=1000 00000

Declaring Pic Microcontroller Port as Input Output

Switching on and off(blink) an led logic is placed in while(1) loop. When ever we press the push button, Current passes through the button towards Port-D Pin#7 and microcontroller reads it as logic-1. As a result Port-B outputs 0 and transistors base receives no current due to which their is no current flow between collector and emitter and led becomes off. Now when ever button is released no current flows through the circuit and Port-D Pin#7 reads it as logic-0, this outputs 1 at Port-B and base of transistors receives some current. Since base receives some current so the channel is on now. Current start flowing through collector to emitter and led becomes on. 

Push button to switch off led and release button to switch on led. You can also reverse the logic. Just change the statement if(Input==0) to if(Input==1). This will on led when Push button is pressed and off led when released. Pushing button and releasing it continuously will cause your led seem blinking.

   
   
  #include <htc.h>
  #define _XTAL_FREQ 20e6
  #define Input RD7
  void main()
  {
   
  TRISB=0x00; //Port-B as Output
  TRISD=0x80; //RD7 as input
  while(1){
   
  if(Input==0)
  PORTB=0xFF;
  else
  PORTB=0x00;
  }
  }
 

Driving heavy Loads(using Transistor) with the same configuration given above

You can also drive heavy loads with the same circuit, just remove led and attach a heavy load like Toy dc motor. Use a transistor which can drive heavy loads. 2n2222 supports 40 volt and 800 mA between collector and emitter. You can drive a load which consumes 40 volt and 800 mA using the circuit given above. 

Some tutorials on driving heavy loads with microcontrollers are below.
Download the Project Code, Folder contains the Hex file as well all the project files. Project is made in MPLAB. You need MPLAB software installed own your PC(Personal Computer) to open the project.
 

The post Push Button as Input and Led as Output with Pic Microcontroller appeared first on PIC Microcontroller.

How to Glow an LED using PWM with PIC Microcontroller- (Part 20/25)

$
0
0

Pulse Width Modulation (PWM) is a technique in which the width of a pulse is modulated keeping the time period of the wave constant. One cycle has a fixed time period called ‘Period’ and a varying on time called ‘Duty cycle’. The entire wave can have two voltages levels either logic 0 or logic 1. The PWM wave is very useful in the digital systems, since this can be used to generate different voltage values other than the logic 0 or logic 1 values. This feature is making use in so many digital systems like DC motor control, audio devices, simple decoration light controls etc.

The PIC18F4550 has an inbuilt PWM module which can generate continuous PWM waves. The Period and the duty cycle of the PWMwave can be adjusted in program. This project explores the PWM module of the PIC18F4550 and tries to glow an LED with varying intensities, which shows that it is possible to generate any required voltage at a pin of a digital microcontroller with the help of PWM waves.

PWM is a digital wave that can be generated using digital circuits which are not capable of generating analog voltages. With the help of the modulation of the width of a pulse in a period of the wave, they can generate any required voltage with the help of a proper filter circuits. Thus the PWM wave is always associated with a filter circuit which has been designed according to the timing details of the pulse.

The following figure shows a microcontroller generating PWM wave which is then used to generate the corresponding analog voltage with the help of a filter circuit.

How to Glow an LED using PWM with PIC Microcontroller- (Part 20 25)

The filter could be any device which can generate the equivalent voltage of a PWM voltage. It normally consists of Low-pass filters, amplifiers, load drivers etc. They generate the voltage and fed that voltage to the load device. In certain cases where the load itself can act as a filter generating the voltage from the PWM wave and drive itself using that voltage. The example of such a devices which can itself act as a PWM filter is DC motor. In this particular project also there is no filter circuit since the aim is to vary the intensity of a glowing LED only. It doesn’t mean that the LED can act as a filter; rather it is the persistence of vision that makes one feel that the intensity of the LED is varying. In this case the LED is glowing normally for the logic1 and logic0 voltages of a PWM, but the variation in the ON time make one feel that the intensity is varying. Here the persistence of vision plays the key role and the filter device is nothing but our eyes itself. 

The PIC18F4550 has four PWM output channels and they are P1A, P1B, P1C and P1D. All of them are capable of generating PWM waves at a time. In this project only one of the PWM channels are using. The P1A is the PWM channel in this particular project. A simple example of the of waves generated at this pin is shown below;

Output PWM Wave at PA1 in PIC18F4550 Microcontroller to Glow LED

As shown in the above figure the ‘Period’ of all the wave remains the same but their ‘Duty-cycle’ varies.

The period of the wave is the sum of the ‘ON time + OFF time’. Duty-cycle is the percentage of time period for which the logic1 voltage exists in a cycle (ON time), starting from the beginning of the cycle.

The PWM is that kind of a wave in which the ON time and OFF time can vary in a cycle but the sum of ‘ON time + OFF time’ remains constant for every cycle.

The period and the duty cycle for a PWM wave can be calculated generally using the following equations;

Period = ON time + OFF time

Duty-cycle = ON time / (ON time + OFF time) = ON time / Period

As shown in the figure, the first PWM wave has a Duty-cycle of 50% which means the on-time is exactly half of that the period of the wave. The second wave has 10% Duty-cycleand the third wave has 90% Duty-cycle. When applied to a proper filter the 50% duty cycle can produce half of the maximum voltage of the pulse. If the maximum voltage (logic 1 voltage) of the pulse is 5V then the 50% duty cycle wave can produce a continuous 2.5V. The 10% duty cycle wave can produce nearly 0 voltages and the 90% duty cycle wave can produce nearly 5V.Thus the wave when applied to a filter can continuously produce a voltage which is the average of the voltage in a single period.

Increasing the Duty-cycle will increase the voltage at the filter device’s output and decreasing the Duty-cycle will decrease the voltage as well

The filter could be anything like a capacitor or inductor. Even though if there is no filter most of the device can generate a corresponding output with a PWM wave resembles that the device is operating at the average voltage of that PWM wave. The LED in this project is the simplest example for such a kind of device.

The registers:

The registers which help in generating the Period and the Duty cycle of the PWM module in a PIC18F4550 are CPR1, PR2 and TMR2. The TMR2 and the PR2 are the timer value and the Pre-scalar value registers of the Timer2 module. They are used to generate the Period of the PWM wave. The CCPR1 is a 10 bit register which can be used to set the duty cycle of the PWM wave.

Suppose one have written the required values into the PR2 and the CCPR1 registers for the Period and Duty cycle of the PWM wave. The TMR2 value is always set to zero once the PWM module is enabled. Once the module is enabled then with each clock the timer2 receives, the value in the TMR2 increases. Hence these registers act like up-counters. This value in the TMR2 register is always under a comparison with the values in the PR2 register and the CCPR1 register like as shown in the following figure;

Block Diagram of Registers to set time and duty cycle of PWM module in PIC

As per the above figure, the Duty-cycle (on-time) is available until the TMR2 value exceeds the CCPR1 value, since the Duty-cycle is the output of the comparator which compares the TMR2 value with the CCPR1 value. The Period of the wave is available further until the value in the TMR2 exceeds the PR2 value since the Period is the output of the comparator which compares the TMR2 value with the PR2 value

Once the value in the TMR2 exceeds that of the PR2 then the TMR2 is cleared to zero and starts counting again. Hence continuous PWM wave with specified duty cycle and Period is available at the PWM output pin. Once can rewrite the CCPR1 value any time to change the duty cycle of the PWM wave so as to change the voltage which the wave is generating at the filter device connected to the PWM pin of the microcontroller.

The Period of the PWM wave in PIC18F4550 given by;

PWM Period = [(PR2) + 1] * 4 * TOSC * (TMR2 Pre-scale Value)

The Duty cycle of the PWM wave in PIC18F4550 is given by;

PWM Duty Cycle = (CCPR1 * TOSC * (TMR2 Pre-scale Value)

CCP1CON

This is the register which controls the PWM operation in PIC18F4550. It can be used to configure the PWM output channels and enable the PWM module in the required mode and can also be used to set the lower two bits of the duty cycle value.

Source: How to Glow an LED using PWM with PIC Microcontroller- (Part 20/25)

Current Project / Post can also be found using:

  • micro controller with pwm output

The post How to Glow an LED using PWM with PIC Microcontroller- (Part 20/25) appeared first on PIC Microcontroller.

How to take input with PIC18F4550 Microcontroller

$
0
0

Any microcontroller based system typically has an input and a corresponding output. Taking simple output with a PIC microcontroller has been explained in LED blinking with PIC18F4550. This article explains how to provide an input to the controller and get a corresponding output using PIC18F4550.

PIC18F4550 has a total of 35 I/O (input-output) pins which are distributed among 5 Ports. Each Port of a PIC microcontroller corresponds to three 8-bit registers (TRIS, PORT & LAT) which should be configured to use the Port for general I/O purpose. For more details, refer LED blinking using PIC.

 
To configure a particular port/pin as input, the corresponding TRIS register/TRIS bit should be set to high (1). For output, the relevant TRIS register/bit should be set to low (0).
 
For example, for PortD
·         To set the entire PortD as input               
TRISD
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value
1
1
1
1
1
1
1
1

Bit Configuration of TRISD Register with PortD as input in PIC18F4550

To set only 3rd pin (RD2) of PortD as input                    
TRISD
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value
1

Bit Configuration of TRISD Register with 3rd pin RD2 of PortD as input in PIC18F4550

To set  1st pin (RD0) as output and 4th pin (RD3) of PortD as input                   
TRISD
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
Value
1
0

Bit Configuration of TRISD Register with 1st pin RD0 as output and 4th pin (RD3) of PortD as input in PIC18F4550

In this program, a tactile switch has been connected on pin RA5 of PortA to provide input to the microcontroller. The input is monitored as an output on LED connected to pin RA0. The connections are shown in the adjoining circuit diagram.

Project Source Code

###

// Program to control an LED using a switch

// Configuration bits
/* _CPUDIV_OSC1_PLL2_1L, // Divide clock by 2
_FOSC_HS_1H, // Select High Speed (HS) oscillator
_WDT_OFF_2H, // Watchdog Timer off
MCLRE_ON_3H // Master Clear on
*/

void main()
{
ADCON1=0x0F; // Set all pins as digital I/O
CMCON=0x07; // Set all comparators as digital I/O
TRISA.RA0=0; // Configure pin RA0 as output
TRISA.RA5=1; // Configure pin RA5 as input
while(1)
{
if(PORTA.RA5) // If input is high
LATA.LATA0=1; // Turn the LED On
else
LATA.LATA0=0; // Turn the LED Off
}
}

###

Project Components

Project Video

Source: How to take input with PIC18F4550 Microcontroller

The post How to take input with PIC18F4550 Microcontroller appeared first on PIC Microcontroller.

How to interface LEDs with PIC Microcontroller (PIC18F4550)

$
0
0

It is necessary to understand basic I/O operations of PIC18F4550 before dealing with its complexities. This article presents a way to take simple output from a PIC microcontroller. This learning would also help in interfacing of external devices with the controller. Here the output from the microcontroller is taken on a set of LEDs which are made to blink in an alternate fashion.

PIC18F4550 has a total of 35 I/O (input-output) pins which are distributed among 5 Ports. The following table shows the names and numbers of I/O pins of these 5 ports: 

Port Name
Number of Pins
Pins
PORTA
7
RA0-RA6
PORTB
8
RB0-RB7
PORTC
7
RC0-RC2, RC4-RC7
PORTD
8
RD0-RD7
PORTE
4
RE0-RE3
 
Fig. 2: I/O pins name and numbers of various ports in PIC 
 
As opposed to a basic 8051 microcontroller like AT89C51 which has most of the port pins serving single function, the port pins of a PIC microcontroller are multiplexed to serve more than one purpose.
 
The 35 I/O pins of PIC18F4550 are also multiplexed with one or more alternative functions of controller’s various peripherals. Each Port of a PIC microcontroller corresponds to three 8-bit registers which should be configured to use the Port for general I/O purpose. These registers are:
 
1.            TRISx: This is a data direction register which sets the direction of each port pin as input or output.
2.            PORTx: This register stores the input level of pins (High or Low). When a pin configured as input, the input signal from external source is read from PORTx register.
3.            LATx: This is output latch register. The data which has to be sent to external hardware as output is stored in LATx register.
 
Port Description:
 
PORTA:
PortA has 7 pins which can be used as both input as well as output pin. The 7th bit is missing from all the three registers. The input and output given to this port are of 8-bit but the 8th bit is internally masked.
 
 
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
TRISA
TRISA6
TRISA5
TRISA4
TRISA3
TRISA2
TRISA1
TRISA0
PORTA
RA6
RA5
RA4
RA3
RA2
RA1
RA0
LATA
LATA6
LATA5
LATA4
LATA3
LATA2
LATA1
LATA0
 
Fig. 3: PortA Configuration in PIC
PORTB:
PortB has 8 pins which can all be used for both input and output operation.
 
 
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
TRISB
TRISB7
TRISB6
TRISB5
TRISB4
TRISB3
TRISB2
TRISB1
TRISB0
PORTB
RB7
RB6
RB5
RB4
RB3
RB2
RB1
RB0
LATB
LATB7
LATB6
LATB5
LATB4
LATB3
LATB2
LATB1
LATB0
 
Fig. 4: PortB Configuration in PIC 
PORTC:
PortC has 7 I/O pins. In PortC, Bit 3 is missing in hardware and Pins 4 & 5 can only be used as input pins. There are no 4th & 5th latch bits in LATC register, so these bits are internally masked during 8-bit write operation on PortC.
 
 
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
TRISC
TRISC7
TRISC6
TRISC2
TRISC1
TRISC0
PORTC
RC7
RC6
RC5
RC4
RC2
RC1
RC0
LATC
LATC7
LATC6
LATC2
LATC1
LATC0
 
Fig. 5: PortC Configuration in PIC 
 
PORTD:
PortD has 8 pins which can all be used for both input and output operation.
 
 
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
TRISD
TRISD7
TRISD6
TRISD5
TRISD4
TRISD3
TRISD2
TRISD1
TRISD0
PORTD
RD7
RD6
RD5
RD4
RD3
RD2
RD1
RD0
LATD
LATD7
LATD6
LATD5
LATD4
LATD3
LATD2
LATD1
LATD0
 
Fig. 6: PortD Configuration in PIC 
PORTE:
PortE has 4 I/O pins. Pin3 can be used as input pin only. RDPU bit is used to enable/disable internal pull-ups of PortD.
 
 
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
Bit 0
TRISE
TRISE2
TRISE1
TRISE0
PORTE
RPDU
RE3
RE2
RE1
RE0
LATE
LATE2
LATE1
LATE0
 
 Fig. 7: PortE Configuration in PIC
 
I/O configuration: 
The TRISx register is configured to set a pin as input or output. The High value (1) sets a pin as input pin and Low value (0) sets a pin as output. An easy way to remember this is to consider the resemblance of 1 with the letter I (for input) and 0 with the letter (for output).        
 
For example suppose a switch is connected at RB0 and an LED is connected to RB7 of PortB. Now the pins 0 & 7 have to be configured as input and output respectively. So the bit TRISB0 is set to 1 to configure RB0 as input pin & bit TRISB7 is set to 0 to configure RB7 as output pin. 
 
TRISB
TRISB7
TRISB6
TRISB5
TRISB4
TRISB3
TRISB2
TRISB1
TRISB0
Value
0
1
 
Fig. 8: TRISB0 set as 1 to configure RB0 as input to interface LED in PIC 
 
The unused bits are set to 0.
 
TRISB
TRISB7
TRISB6
TRISB5
TRISB4
TRISB3
TRISB2
TRISB1
TRISB0
Value
0
0
0
0
0
0
0
1
 
So the overall value of TRISB register becomes:
Using this knowledge, the objective of this article can be achieved which is to glow a set of LEDs in alternate blinking fashion. The LEDs here are connected to PORTB pins as shown in the circuit diagram.
 
Programming steps: 
 
1.      Configure the TRISB register to make PortB as output port.
2.      Set all the bits of LATB register High (1) to glow all LEDs.
3.      Provide some delay.
4.      Set all the bits of LATB register Low (0) to turn off the LEDs.
5.      Provide some delay.
6.      Repeat the process from step 2.

Project Source Code

###

/******************Chip config*******************

PLLDIV = 5
CPUDIV = OSC1 / 2
USBDIV = 2
FOSC = HIGH_SPEED HS
FCMEN = OFF
IESO = OFF
PWRT = OFF
BOR = OFF
BORV = 3
VREGEN = OFF
WDT = OFF
WDTPS = 1:32768
CCP2MX = ON
PBADEN = OFF
LPT1OSC = OFF
MCLRE = OFF
STVREN = ON
LVP = OFF
ICPRT = OFF
XINST = OFF
DEBUG = OFF
CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF
CPB = OFF
CPD = OFF
WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF
WRTC = OFF
WRTB = OFF
WRTD = OFF
EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF
EBTRB = OFF

******************Chip config*******************/

#include <p18cxxx.h>

void delay_ms ( int delay );

void delay_ms ( int delay )
{
int ms, i;

for ( ms = 0; ms < delay; ms ++ )
for ( i = 0; i < 5; i ++ );
}

void main()
{
TRISB = 0x00; // Set PORTB as output PORT
LATB = 0xFF; // Set PORTB high initially (All LEDs on)

while ( 1 )
{
LATB = ~LATB; // Toggle the value of PORTB
delay_ms ( 1000 ); // Delay of 1 sec
}
}
###

Circuit Diagrams

Circuit Diagrams ......

Project Components

Project Video

Source: How to interface LEDs with PIC Microcontroller (PIC18F4550)

The post How to interface LEDs with PIC Microcontroller (PIC18F4550) appeared first on PIC Microcontroller.

PWM Signal on Nuvoton N76E003 Microcontroller – LED Dimming using Duty Cycle Control

$
0
0

Pulse Width Modulation (PWM) is a commonly used technique in microcontrollers to produce a continuous pulse signal with a defined frequency and duty cycle. In short, PWM is about changing the width of a pulse while the frequency is constant.

PWM Signal on Nuvoton N76E003 Microcontroller - LED Dimming using Duty Cycle Control

A PWM signal is mostly used in controlling a servo motor or brightness of an LED. Also, since microcontrollers can only provide Logic 1 (High) or Logic 0 (Low) on its output pins, it cannot provide a varying analog voltage unless a DAC or Digital to Analog converter is used. In such a case, the microcontroller can be programmed to output a PWM with a varied duty cycle which can then be converted to the varying analog voltage. We have previously used PWM peripheral in many other microcontrollers as well.

In this tutorial, we will interface an LED that will be controlled using this PWM signal from the N76E003 microcontroller unit. We will evaluate what kind of hardware setup we require and how we should program our microcontroller. Before that, let’s understand some basics of a PWM Signal.

Basics of PWM Signal

In the below image a constant PWM signal is shown.

Basics of PWM Signal

The above image is nothing but a constant square wave with the same ON time and the same OFF time. Suppose, the total period of the signal is 1 Second. Thus the on time and off time is 500ms. If an LED is connected across this signal, the LED will turn on for 500ms and turn off for 500ms. Therefore, in perspective view, the LED will lit up with half of the actual brightness if it is turned on to a direct 5V signal without any off time.

Now as shown in the above image, if the duty cycle is changed, the LED will lit up with 25% of actual brightness using the same principle as discussed before. If you want to know more and learn about Pulse Width Modulation (PWM), you can check out the linked article.

Hardware Setup and Requirement

As the requirement of this project is to control LED using PWM. An LED is required to be interfaced with N76E003. Since an LED is available in the N76E003 development board, it will be used in this project. No other components are required.

Not to mention, we need the N76E003 microcontroller based development board as well as the Nu-Link Programmer. An additional 5V power supply unit may be required if the programmer is not used as a power source.

Circuit Diagram for Nuvoton N76E003 Microcontroller LED Dimming

As we can see in the below schematic, the Test LED is available inside the development board and it is connected on port 1.4. On the extreme left, the programming interface connection is shown.

Circuit Diagram for Nuvoton N76E003 Microcontroller LED Dimming

PWM Pins on N76E003 Nuvoton Microcontroller

The N76E003 has 20 pins out of which 10 pins can be used as PWM. The below images is showing the PWM pins highlighted in the red square box.

PWM Pins on N76E003 Nuvoton Microcontroller

As we can see, the highlighted PWM pins can also be used for other purposes. However, this other purpose of the pins will not be available when the pins are configured for PWM output. Pin 1.4 which is used as a PWM output pin, it’ll lose the other functionality. But, that is not a problem as another functionality is not required for this project.

The reason behind choosing pin 1.4 as an output pin is because the inbuilt Test LED is connected on that pin in the development board, thus we do not require external LEDs. However, in this microcontroller out of 20 pins, 10 pins can be used as a PWM output pin and any other PWM pins can be used for output related purposes.

PWM Registers and Functions in N76E003 Nuvoton Microcontroller

N76E003 uses system clock or Timer 1 overflow divided by a PWM clock with Prescaler selectable from 1/1 ~ 1/128. The PWM period can be set using the 16-bit period register PWMPH and PWMPL register.

The microcontroller has six individual PWM registers that generate six PWM signals called PG0, PG1, PG2, PG3, PG4, and PG5. However, the period is same for each PWM channels because they share the same 16-bit period counter but the duty cycle of each PWM can be different from others as each PWM uses different 16-bit duty cycle register named as {PWM0H, PWM0L},{PWM1H, PWM1L}, {PWM2H, PWM2L},{PWM3H, PWM3L},{PWM4H, PWM4L}, and {PWM5H, PWM5L}. Thus, in N76E003, six PWM outputs can be generated independently with different duty cycles.

Unlike with other microcontrollers, enabling the PWM does not set the I/O pins into their PWM output automatically. Thus, the user needs to configure the I/O output mode.

So, whatever is required for the application, the first step is to determine or select which one or two or even more than two I/O pins as PWM output. After selecting one, the I/O pins need to be set as Push-Pull mode or Quasi-bidirectional for generating the PWM signal. This can be selected using the PxM1 and PxM2 register. These two registers set the I/O modes where the x stands for the Port number (For example, Port P1.0 the register will be P1M1 and P1M2, for P3.0 it will be P3M1 and P3M2, etc.)

The configuration can be seen in the below image-

PWM Registers and Functions in N76E003 Nuvoton Microcontroller

Then, the next step is to enable the PWM in that particular I/O pin(s). To do this, the user needs to set the PIOCON0 or PIOCON1 registers. The register is dependent on the pin mapping as PIOCON0 and PIOCON1 control different pins dependent on the PWM signals. The configuration of these two registers can be seen in the below image- 

Source: PWM Signal on Nuvoton N76E003 Microcontroller – LED Dimming using Duty Cycle Control

The post PWM Signal on Nuvoton N76E003 Microcontroller – LED Dimming using Duty Cycle Control appeared first on PIC Microcontroller.

Timers on Nuvoton N76E003 Microcontroller – Blink LED using Timer ISR and Timer Delay

$
0
0

In our previous Nuvoton Microcontroller tutorials, we used a basic LED blinking program as a getting started guide and also interfaced GPIO as an input to connect a tactile switch. With that tutorial, we are fully aware of how to configure the Keil project and set up the environment for programming N76E003 Nuvoton microcontroller. It is time to use an internal peripheral of the microcontroller unit and move a little bit further by using the inbuilt Timer of the N76E003.

Timers on Nuvoton N76E003 Microcontroller - Blink LED using Timer ISR and Timer Delay

In our previous tutorial, we only used a software delay to blink an LED, so in this tutorial, we will learn how to use the Timer delay function as well as the Timer ISR (Interrupt Service Routine) and blink two individual LEDs. You can also check out the Arduino Timer Tutorial and PIC Timer tutorial to check how to use timers with other microcontrollers. Without wasting much time let’s evaluate what kind of hardware setup we require.

Hardware Setup and Requirement

As the requirement of this project is to learn Timer ISR and the timer delay function, we will use two LEDs, out of which one will be blinked using timer delay in the while loop and another one will be blinked inside the ISR function.

Since an LED is available in the N76E003 development board, this project requires one additional LED and the current limiting resistor to limit the LED current. The components we require –

  1. Any color of the LED
  2. 100R resistor

Not to mention, other than the above components, we need N76E003 microcontroller based development board as well as the Nu-Link Programmer. Additionally, breadboard and hookup wires are also required for connecting all components.

Circuit Diagram for LED Interfacing with Nuvoton N76E003

As we can see in the below schematic, the Test LED is available inside the development board and it is connected on port 1.4. An additional LED is connected to port 1.5. The resistor R3 is used to limit the LED current. On the extreme left, the programming interface connection is shown.

Circuit Diagram for LED Interfacing with Nuvoton N76E003

Timer Pins on Nuvoton N76E003

The pin diagram of N76E003 can be seen in the below image-

Timer Pins on Nuvoton N76E003

As we can see, each pin has different specifications and each pin can be used for multiple purposes. However, pin 1.5 which is used as an LED output pin, it’ll lose the PWM and other functionality. But, that is not a problem as another functionality is not required for this project.

The reason behind choosing pin 1.5 as output and pin 1.6 as input is because of the nearest availability of GND and VDD pins for easy connection. However, in this microcontroller out of 20 pins, 18 pins can be used as a GPIO pin and any other GPIO pins can be used for output and Input related purposes, except pin 2.0 which is dedicatedly used for Reset input and it cannot be used as output. All GPIO pins can be configured in the below-described mode.

As per the datasheet, PxM1.n, and PxM2.n are two registers that are used to determine the control operation of the I/O port. Since we are using LED and we require the pin as general output pins, therefore we will use Quasi-bidirectional mode for the pins. 

Timer Registers in Nuvoton N76E003

The timer is an important thing for any microcontroller unit. Microcontroller comes with an in-built timer peripheral. The nuvoton N76E003 also comes with 16-bit timer peripherals. However, each timer is used for different purposes, and before using any timer interface it is important to know about the timer.

Types of Times in Nuvoton N76E003

Timer 0 and 1:

These two timers timer0 and timer1 are identical with 8051 timers. These two timers can be used as a general timer or as counters.  These two timers operate in four modes. In Mode 0, those timers will operate in 13-bit Timer/Counter mode. In Mode 1, the resolution bit of those two timers will be 16-bit. In Mode 2, timers are configured as an auto-reload mode with an 8-bit resolution. In Mode 3, the timer 1 is halted and timer 0 can be used as a counter and timer at the same time.

 

Out of these four modes, Mode 1 is used in most cases. These two timers can use the Fsys (System Frequency) in fixed or prescaled mode (Fys / 12). It can also be clocked from an external clock source.

Timer 2:

Timer 2 is also a 16-Bit timer that mainly used for waveform capture. It also uses the system clock and can be used in different applications by dividing the clock frequency using 8 different scales. It can also be used in compare mode or to generate PWM.

Same as like Timer 0 and Timer 1, Timer 2 can be used in auto-reload mode.

Timer 3:

Timer 3 is also used as a 16-bit timer and it is used for the baud rate clock source for the UART. It also has an auto-reload feature. It is important to use this timer only for Serial communication (UART) if the application requires UART communication. It is advisable not to use this timer for other purposes in such a case due to the conflicting process in the timer setup.

Watchdog Timer:

Watchdog Timer can be used as a standard 6-bit timer but it is not used for this purpose. The use of Watchdog timer as a general-purpose timer is applicable for low power consumption applications where the microcontroller stays mostly in idle mode.

Watchdog Timer, as the name suggests, always checks whether the microcontroller is working properly or not. In the case of a hanged or halted microcontroller, WDT (Watchdog Timer) reset the microcontroller automatically which ensures that the microcontroller runs in a continuous code flow without getting stuck, hanged or in halted situations.

Self Wake-Up Timer:

This is another timer peripheral that serves a dedicated timing process the same as a watchdog timer. This timer, wake-up the system periodically when the microcontroller is running in low power mode.

This timer peripheral can be used internally or using external peripherals to wake up the microcontroller from sleep mode. For this project, we will use Timer 1 and Timer 2.

Programming Nuvoton N76E003 Microcontroller for Timers

Setting the Pins as Output:

Let’s start with the output section first. We are using two LEDs, one is the onboard LED, named Test, and connected with the port P1.4 and an external LED connected with the pin P1.5.

Therefore, these two pins are configured as an output pin to connect those two LEDs by using the below code snippets.

#define Test_LED P14
#define LED1 P15

These two pins are set as Quasi-bidirectional pin in the setup function.

void setup (void){
                P14_Quasi_Mode;
                P15_Quasi_Mode;
                }

Setting the Timer Function:

In the setup function, Timer 2 is needed to be configured to get the desired output. For this, we will set the T2MOD register with a 1/128 clock dividing factor and use it in an auto-reload delay mode. Here is the overview of T2MOD register-

The 4,5, and 6th-bit of the T2MOD register set the timer 2 clock divider and the 7th-bit set the auto-reload mode. This is done using the below line –

TIMER2_DIV_128;
TIMER2_Auto_Reload_Delay_Mode;

These two lines are defined in Function_define.h file as

#define                  TIMER2_DIV_128                               T2MOD|=0x50; T2MOD&=0xDF
#define TIMER2_Auto_Reload_Delay_Mode              T2CON&=~SET_BIT0; T2MOD|=SET_BIT7; T2MOD|=SET_BIT3

Now, these lines set the timing value required for the Timer 2 ISR.

RCMP2L = TIMER_DIV128_VALUE_100ms;
RCMP2H = TIMER_DIV128_VALUE_100ms>>8;

Which is further defined in Function_define.h file as-

TIMER_DIV128_VALUE_100ms                     65536-12500       //12500*128/16000000 = 100 ms

So, 16000000 is the crystal frequency of 16 Mhz which is setting up the 100 ms time delay.

Below two lines will empty the Timer 2  Low and High bytes.

TL2 = 0;
TH2 = 0;

Finally below code will enable the timer 2 interrupt and start the Timer 2.

set_ET2;                                    // Enable Timer2 interrupt
set_EA;
set_TR2;                                    // Timer2 run

The complete setup function can be seen in the below codes-

void setup (void){
P14_Quasi_Mode;
P15_Quasi_Mode;
TIMER2_DIV_128;
TIMER2_Auto_Reload_Delay_Mode;
RCMP2L = TIMER_DIV128_VALUE_100ms;
RCMP2H = TIMER_DIV128_VALUE_100ms>>8;
TL2 = 0;
TH2 = 0;
set_ET2;                                    // Enable Timer2 interrupt
set_EA;
set_TR2;                                    // Timer2 run
}

Timer 2 ISR Function:

The Timer 2 ISR function can be seen in the below code.

void Timer2_ISR (void) interrupt 5
{
                  clr_TF2;                                             //Clear Timer2 Interrupt Flag
                  LED1 = ~LED1;                                                                                                                                                                                                                                  // LED1 toggle, connected in P1.5;   
}

Clr_TF2 Will clear the Timer 2 interrupt flag and the LED will get toggled whenever the ISR Function is called. As the interrupt is set for 100 ms, the LED will blink in a 100 ms time intervals.

Main Function and while loop:

A Hardware, if connected with the power and working perfectly then it should give output continuously and the application never stops. It does the same thing for infinite times. Here comes the function while loop. The application inside the while loop runs infinitely. At first, the setup function is called.

Source: Timers on Nuvoton N76E003 Microcontroller – Blink LED using Timer ISR and Timer Delay

The post Timers on Nuvoton N76E003 Microcontroller – Blink LED using Timer ISR and Timer Delay appeared first on PIC Microcontroller.


Simple GPIO Functions on Nuvoton N76E003 – LED Blinking and Controlling LED using a Push Button

$
0
0

In our previous tutorial, we used a basic LED blinking program as a getting started with N76E003 guide, we already learned how to configure the Keil IDE and set up the environment for programming the nuvoton microcontroller unit N76E003. It is the time to move a little bit further and use the basic GPIO interface for controlling additional hardware. If you are interested you can also check other microcontroller GPIO tutorials that are listed below-

Simple GPIO Functions on Nuvoton N76E003 - LED Blinking and Controlling LED using a Push Button

Since in our previous tutorial, we only used an LED to blink by using an IO pin as an output. In this tutorial, we will learn how to use another IO pin as an input and control an additional LED. Without wasting much time, let’s evaluate what kind of hardware setup we require.

Hardware Setup and Requirement

As a switch needs to be used as input, the first thing we require is a push button. We also require an additional LED to be controlled by that push button. Other than these two, we also require a resistor to limit the LED current and an additional resistor for the pull-down purposes across the pushbutton. This will be further demonstrated in the schematic section. The components we require –

  1. A push-button (any kind of momentary switch specifically – Tactile switch)
  2. Any color of the LED
  3. 4.7k resistor for pull-down purposes
  4. 100R resistor

Not to mention, other than the above components, we need N76E003 microcontroller-based development board as well as the Nu-Link Programmer. Additionally, breadboard and hookup wires are also required for connecting all components as shown below.

Hardware Setup and Requirement

N76E003 LED and Push Button Interface Circuit

As we can see in the below schematic, the Test LED that is inside the development board is connected on the port 1.4 and an additional LED is connected on the port 1.5. The resistor R3 is used to limit the LED current.

N76E003 LED and Push Button Interface Circuit

In pin 1.6, a push-button named SW is connected. Whenever the button is pressed, the pin will become high. Otherwise, it will become low by the 4.7K pull-down resistor R1. You can learn more about pull-up and pull-down resistors if you are new to this concept.

The pin is also a program related pin that is accessed by the programmer. It is used to send program data. However, we will see the reason behind selecting those pins as well as get fair information about the pin mapping of N76E003.

N76E003 Pin-Out Diagram

The pin diagram of N76E003 can be seen in the below image-

N76E003 Pin-Out Diagram

Pin Diagram of N76E003

As we can see, each pin has multiple functions and can be used for different purposes. Let’s take an example. The pin 1.7 can be used as an interrupt, or analog input or as a general-purpose input-output operation. Thus, if any pin is used as I/O pins, then the respective functionality will not be available.

Due to this, the pin 1.5 which is used as an LED output pin, it’ll lose the PWM and other functionality. But that is not a problem as another functionality is not required for this project. The reason behind choosing pin 1.5 as output and pin 1.6 as input, because of the nearest availability of GND and VDD pins for easy connection.

However, in this microcontroller out of 20 pins, 18 pins can be used as a GPIO pin. The pin 2.0 is dedicatedly used for Reset input and it cannot be used as output. Other than this pin, all pins can be configured in the below-described mode.

As per the datasheet, PxM1.n, and PxM2.n are two registers that are used to determine the control operation of the I/O port. Now, coming to writing and reading a GPIO port is a completely different thing. Because writing to a port control register changes the latching state of the port, whereas reading the port gets the status of the logic state. But for reading a port, it must be set into an input mode.

Simple GPIO Control Program for N76E003

The complete program used in this tutorial can be found at the bottom of this page, the explanation of the code is as follows.

Setting the pin as input

Let’s start with the input first. As discussed just before, to read the status of a port, it needs to be set as input. Therefore, as we have selected P1.6 as our input switch pin, we have denoted it through the below line of code snippet.

#define SW P16

This same pin needs to be set as input. Thus, on the setup function, the pin is set as input using the below line.

void setup (void){
                P14_Quasi_Mode;
                P15_Quasi_Mode;
                P16_Input_Mode;
                }

This line P16_Input_Mode; is defined in the Function_define.h header file in the “BSP include library” that sets the pin bit as P1M1|=SET_BIT6; P1M2&=~SET_BIT6. The SET_BIT6 is also defined in the same header file as-

#define SET_BIT6               0x40

Setting the pins as output  

Same as the input pin, the output pin that is used by the onboard Test LED and the external LED1 is also defined in the first section of the code with the respective PINs.

#define Test_LED P14
#define LED1 P15

Those pins are set as an output in the setup function using the below lines.

void setup (void){
                P14_Quasi_Mode; // Output
                P15_Quasi_Mode; // Output
                P16_Input_Mode;
                }

These lines are also defined in the Function_define.h header file where it sets the pin bit as P1M1&=~SET_BIT4; P1M2&=~SET_BIT4The SET_BIT6 is also defined in the same header file as-

#define SET_BIT4               0x10

Infinite While loop 

A Hardware, if connected with the power and working perfectly that should give output continuously, the application never stops. It does the same thing for infinite times. Here comes the function of an infinite while loop. The application inside the while loop runs infinitely.

  while(1){           
             Test_LED = 0;
            sw_delay(150);
            Test_LED = 1;
            sw_delay(150);          
             if(SW == 1){
                         LED1 = 0;
             }
             else {
                         LED1 = 1;
            }
}
}

The above while loop blinks the led as per the sw_delay value and also checks the status of the SW. If the switch is pressed, the P1.6 will be high, and thus when it is pressed, the read status will be 1. In this situation, for the time, the switch is pressed and the port P1.6 remains high, the LED1 will glow.

Programming N76E003 and Verifying Output

In our getting started with N76E003 tutorial, we learned how to program the N76E003 already, so we will just repeat the same steps here to program our board. The code compiled successfully and returned 0 warning and 0 Errors and flashed using the default flashing method by the Keil.

Programming N76E003 and Verifying Output

As you can see in the above image, our external LED turns on when I press the push button. The complete working of the project can be found in the video linked below. Hope you enjoyed the tutorial and learned something useful if you have any questions, leave them in the comment section below. You can also use our forums to ask other technical questions.

 
Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "N76E003.h"
#include "SFR_Macro.h"
#include "Function_define.h"
#include "Common.h"
#include "Delay.h"
#define Test_LED P14
#define LED1 P15
#define SW P16
void setup (void);
void sw_delay (int ms);
 
void main(void){
    setup();
    while(1){   <span style="white-space:pre"> </span>
   <span style="white-space:pre"> </span> Test_LED = 0;
sw_delay(150);
Test_LED = 1;
sw_delay(150);
if(SW == 1){
LED1 = 0;
}
   <span style="white-space:pre"> </span> else {
LED1 = 1;
}
 
}
}
 
// Software-based delay. Time is not accurate.
void sw_delay (int ms){
int a, b;
for (a=0; a<1296; a++){
for (b=0; b<ms; b++);
}
 
}
 
//This is the setup file before application runs
void setup (void){
P14_Quasi_Mode;
P15_Quasi_Mode;
P16_Input_Mode;
}
 
 

The post Simple GPIO Functions on Nuvoton N76E003 – LED Blinking and Controlling LED using a Push Button appeared first on PIC Microcontroller.

Getting Started With Nuvoton N76E003 using Keil – Blinking an LED

$
0
0

There are lots of microcontrollers available from reputed companies such as PIC, Texas Instruments, ST and the list goes on. But when we differentiate those microcontrollers with form factor vs features vs price, it gets hectic to choose one. However, nuvoton is a Taiwan based semiconductor company that was spun-off as a Winbond affiliate in 2008. The company offers very useful microcontrollers, mixed-signal chips, microprocessors with extremely high specification. But the most important thing is that it provides all features at a very low-cost margin. Thus, during the development of the production phase, the nuvoton micro-controller is getting an upper edge due to the low price and high feature supports.

Getting Started With Nuvoton N76E003 using Keil – Blinking an LED

For example, nuvoton N76E003 is a 20-pin microcontroller unit that supports 18 I/O pins out of 20 with features like UARTs, I2C, 6-Ch PWM, SPI, wake up functions, Brownout detectors with an 8-bit high performance 8051-based microcontroller unit. Now you should be wondering what is the price? It’s less than 0.4$ (30 Rs) only. Additionally, it doesn’t require an oscillator, also, since it’s equipped with 16 MHz internal RC oscillators.

In this series of tutorials, we will learn how to program the N76E003 microcontroller unit, more specifically the N76E003at20 microcontroller. Since it is a very cheaper one and has a wide range of features, you can find this microcontroller interesting if you are a beginner, or doing hobby projects or a professional one. In this specific tutorial, we will learn how to set-up the N76E003 programming environment as well as how to write the first hello world program of the embedded – blinking an LED.

Selecting the Hardware and Software Development Tools

Since the microcontroller is finalized with Nuvoton N76E003at20, it’s time to find out the proper hardware and software that is required for programming the microcontroller. Let’s start to find out how to create the programming environment of the N76E003.

N76E003 Development Hardware

The official development board for nuvoton N76E003 is the NuTiny-N76E003 SDK board with a programmer. But since this board is hard to find in India, and it does cost high, a standard bare minimum development board is available online. The image of the N76E003 Development board that we will use in this tutorial is shown below. 

N76E003 Development Hardware

As we can see in the schematic, the development board doesn’t have any kind of voltage regulator be it linear or LDO. However, it has a filter capacitor at the input. It also has a power LED and a reset button to reset the microcontroller unit. There is also a test LED available that can be configured using the code. Other than this, external crystal and required capacitors pad are also available without the components that can be very useful during further development where the external oscillator is required.

Nu-Link as N76E003 Programmer

For programming this microcontroller, we are using an unofficial Nu-link programmer which is a low cost alternative available in the online stores. However, for those who are willing to use the official Nu-link programmer, it is available for purchase as the Nu-Tiny SDK development board.

Nu-Link as N76E003 Programmer

The programmer that we will use in our tutorial is shown above. It has Macro-USB connectivity, Offline programming button, and status indicator using 4 LEDs (ICE, ISP, RED, and GREEN).

IDE and Compiler for N76E003 Microcontroller

Getting the proper IDE and compiler is an important thing for any microcontroller programming. For the industry-leading microcontroller manufacturers, such as a microchip, nordic, STMicroelectronics – they all provide free c compiler and IDE. But for nuvoton programming, this is the one thing that lags. Since it is an 8051 based microcontroller, it can be programmed using Keil u vision with C51 compiler, or IAR Embedded workbench. But there is a catch. Both tools are great to do the job, but they are not free. There are trial and evaluation versions of these tools available and satisfy the job of programming nuvoton N76E003.

We have chosen Keil Micro Vision since the UI is easy to understand, good to configure and the workspace is really useful. It also comes with the C51 compiler that will compile the code for 8051 architecture.

However, to flash the program to the microcontroller, we will use the Nu-link Keil driver interface inside the Keil micro vision. This makes a one-click flash environment inside the Keil workspace. It is very useful to save time to flash the code into the chip. We will discuss more on this further.

N76E003 BSP Library

Other than the compiler and IDE, another important thing that is required for programming the N76E003 is the Board Support Package (BSP) Library. This is the Board support files for the microcontroller. This includes useful header files, peripheral libraries, SFR Macros, Hardware-level functions, etc.

 

So, these are my choices for Software and Hardware, let me know in the comment section if you think some other software would have been a better choice and why. I would like to explore other options as well.

Downloading Required Softwares

Now it is time to download the required files to create the environment ready for programming. Here is the list of important software that is required to be downloaded before installing anything. Just provide the required information on the Keil-C51 download page.

Install the Keil u Vision

After downloading the Keil micro vision, install it in the default directory. It will look something similar like this-

Install the Keil u Vision

Just press the next and let it install.

Install the Nu-link Keil Driver

Open the downloaded Nu-link Keil driver. After opening the Keil driver, select the language and press next. The screen will look similar to this with the default directory automatically being set.

Install the Nu-link Keil Driver

Do not change the path and press next. In this section, it will ask about the default location of Keil Microvision that was installed in the previous step.

The default Keil installed location will be shown. Do not change it to anything else and press next. It will now install the Nu-Link driver for Keil. After installation is done, it will show a window like this-

Tick the optional choice – Install Nu-Link USB Driver 1.6. Do not forget to tick this. It is not an optional thing but an important driver for the programmer and it is needed.

Source: Getting Started With Nuvoton N76E003 using Keil – Blinking an LED

The post Getting Started With Nuvoton N76E003 using Keil – Blinking an LED appeared first on PIC Microcontroller.

GPIO Functions on STM8S using Cosmic C and SPL – Blinking and Controlling LED with Push Button

$
0
0

For microcontrollers, an LED blinking program is equivalent to the “hello world” program. In our previous tutorial, we learned how to get started with STM8S103F3 Development Board and how to set up the IDE and compiler to program our STM8S controllers. We have also learned how to use the standard peripheral libraries, and how to compile and upload the code into our microcontroller. With all the basics covered, lets actually start writing code. In this tutorial, we will learn how to perform general GPIO functions on STM8S controllers. The board already has an onboard LED connected to pin 5 of port B, we will learn how to blink this LED and also add an external LED and control it with a push-button. If you are completely new, it is highly recommended to read the previous tutorial before you proceed any further.

GPIO Functions on STM8S using Cosmic C and SPL – Blinking and Controlling LED with Push Button

Getting the Hardware Ready

Before we dive into the program, let get the hardware connections ready. As mentioned early, we will be using two LEDs here, one is an onboard LED which will blink continuous and the other is an external LED which will be toggled with a push button. The idea is to learn all the GPIO functionality in a simple set up. The on-board Led is already connected to PB5 (pin5 of PORTB), so I have just connected an LED to PA3 and a push-button to PA2, as you can see in the diagram below.

Getting the Hardware Ready

But, of all the output pins available on our controlled why did I select PA3 for output and PA2 for input? The questions are valid and I will explain that later in this article. My hardware set-up for this tutorial is shown below. As you can see, I have also connected my ST-link programmer to programming pins which will not only program our board but will also act as a power source. 

Understanding GPIO Pinouts on STM8S103F

Now coming back to the question, why PA2 for input and why PA3 for output? To understand that, let’s take a closer look at the pinout of the microcontroller which is shown below.

As per the pinout diagram, we have four ports on our microcontroller, namely, PORT A, B, C, and D denoted by PA, PB, PC, and PD respectively. Each GPIO pin is also clubbed with some other special functionality. For example, the PB5 (pin 5 of PORT B) can not only work as a GPIO pin but also as an SDA pin for I2C communication and as a Timer 1 output pin. So, if we use this pin for simple GPIO purposes like connecting an LED, then we won’t be able to use I2C and the LED at the same time. Sadly, the on-board LED is connected to this pin, so we don’t have much of a choice here, and in this program, we are not going to use I2C, so it’s not much of a problem.

Pinout Description and Tips for STM8S103F GPIO Selection

Truly speaking, it would not hurt to use PA1 an input pin and it would just work pin. But I deliberately brought this up to provide me an opportunity to show you some common traps that you might fall into when selecting GPIO pins on a new microcontroller. The best to avoid the traps is to read the pin details and pin description provided in the STM8S103F3P6 datasheet. For the STM8S103F3P6 microcontroller pin description details that are mentioned in the datasheet are shown below images.

The input pins on our microcontroller can either be floating or weak pull-up and the output pins can either be Open Drain or Push-pull. The difference between Open Drain and Push-Pull Output pins is already discussed, hence we won’t get into details of that. To put it simple, an Open Drain output pin can make the output only as low not as high, while a push-pull output pin can make the output both as high as well as high.

Apart from that from the above table, you can also notice that an output pin can either be Fast output (10 Mhz) or Slow Output (2 MHz). This determines the GPIO Speed, if you want to switch your GPIO pins between high and low very fast, then we can choose Fast output.

Some GPIO pins on our controller support True Open Drain (T) and High Sink Current (HS) as mentioned in the above image. A considerable difference between Open Drain and True Open Drain is that the output connected to open drain cannot be pulled high more than the operating voltage of microcontroller (Vdd) while a true open-drain output pin can be pulled higher than Vdd. Pins with High Sink Capability means that it can sink more current. The source and sink current of any GPIO HS pin is 20mA, while the power line can consume up to 100 mA.

Taking a closer look on the above image, you will notice that almost all GPIO pins are High Sink Current (HS) type except for PB4 and PB5 which are True Open Drain Type(T). This means that these pins cannot be made high, they will not be able to provide 3.3V even when the pin is made high. This is why the onboard led is connected to a 3.3V and grounded through PB5 instead of powering it directly from the GPIO pin. 

Source: GPIO Functions on STM8S using Cosmic C and SPL – Blinking and Controlling LED with Push Button

The post GPIO Functions on STM8S using Cosmic C and SPL – Blinking and Controlling LED with Push Button appeared first on PIC Microcontroller.

USB RGB LED STRIP CONTROL PIC18F2550 MOSFET DRIVER CIRCUIT

$
0
0

RGB LED control circuit based on the PIC18F2550 microcontroller communication is done via the computer’s USB port can be controlled RGB LED strip through the program (rapid color change, slow color change) LEDs can change color according to the… Electronics Projects, USB RGB Led Strip Control PIC18F2550 Mosfet Driver Circuit “led projects, microchip projects, microcontroller projects, pic18f2550 projects,

USB RGB LED STRIP CONTROL PIC18F2550 MOSFET DRIVER CIRCUIT

RGB LED control circuit based on the PIC18F2550 microcontroller communication is done via the computer’s USB port can be controlled RGB LED strip through the program (rapid color change, slow color change)

LEDs can change color according to the ambient temperature DS1821 temperature sensor is used for sensing temperature values ​​can be determined on the program. PIC18F2550 IRFZ 34N MOSFET outputs rgb led strip of reinforced (12volt 13.5cm) driven

USB PIC18F2550 RGB LED STRIP

Source: steffenschuette.de RGB Led Strip Mosfet Driver Circuit alternative link :

FILE DOWNLOAD LINK LIST (in TXT format): LINKS-10381.zip

Source: USB RGB LED STRIP CONTROL PIC18F2550 MOSFET DRIVER CIRCUIT 

The post USB RGB LED STRIP CONTROL PIC18F2550 MOSFET DRIVER CIRCUIT appeared first on PIC Microcontroller.

LED HEART ANIMATION CIRCUIT PIC12F675 MICROCONTROLLER

$
0
0

Hi, this article will save you from the hard work of you and your fatigue will assign a kind of circuit that you desire and willingness to solder smoke to relieve a little I offer a simple light heart…. Electronics Projects, Led Heart Animation Circuit PIC12F675 Microcontroller “led projects, microchip projects, microcontroller projects,

LED HEART ANIMATION CIRCUIT PIC12F675 MICROCONTROLLER

Hi, this article will save you from the hard work of you and your fatigue will assign a kind of circuit that you desire and willingness to solder smoke to relieve a little I offer a simple light heart.

This solder smell after a long period creates a desire in me that you wont know it is there. Also loved ones on special occasions that make Chinese goods and hand crafted souvenirs rather than your own would be nice to donate a heart. (Though the PIC s Chinese goods on the LEDs, but you get the job you have in one another in their labor)

LED HEART ANIMATION CIRCUIT TEST

LED HEART CIRCUIT PROTEUS ISIS SCHEMATIC

LED HEART CIRCUIT PROTEUS ISIS SCHEMATIC

author: Aytaç DÜRGEN – The source code and a heart Animation project pic12f675 Led proteus simulation files:

FILE DOWNLOAD LINK LIST (in TXT format): LINKS-10261.zip

Source: LED HEART ANIMATION CIRCUIT PIC12F675 MICROCONTROLLER

The post LED HEART ANIMATION CIRCUIT PIC12F675 MICROCONTROLLER appeared first on PIC Microcontroller.

CCS C MATRIX LED DISPLAY SNAKE GAME CIRCUIT PIC16F877 MICROCONTROLLER

$
0
0

Matrix LED display snake game PIC16F877 microcontroller based on the software the ccs c prepared by the matrix led display via the Display button with the game is played application Project Articles Sharing section were delivered file sending application… Electronics Projects, CCS C Matrix LED Display Snake Game Circuit PIC16F877 Microcontroller “microchip projects, microcontroller projects, pic16f877 projects,

Matrix LED display snake game PIC16F877 microcontroller based on the software the ccs c prepared by the matrix led display via the Display button with the game is played application Project Articles Sharing section were delivered file sending application that prepares individuals Thank you

CCS C SNAKE GAME CIRCUIT TEST

PIC16F877 prepared by the snake with a snake oyunu.4 button was programmed with the control yapılmakta.ccs CA.

Material List:

2 x 3 mm, 7 × 5 matrix display common anode
5 buttons
5 pcs 10k resistors
1 4 MHz crystal
1 PIC16F877

Note: If you want to use Half-common-cathode display change as do some of the code is required. Column C port selection function should be rearranged and “~” in front of the information sent terslenerek with “~” sign should be removed and that information must be submitted before reversal.

author: recaisinekli.com Matrix LED display snake game application files (source ccs c, hex codes and proteus ares pcb circuit diagram file:

FILE DOWNLOAD LINK LIST (in TXT format): LINKS-10232.zip

Source: CCS C MATRIX LED DISPLAY SNAKE GAME CIRCUIT PIC16F877 MICROCONTROLLER

The post CCS C MATRIX LED DISPLAY SNAKE GAME CIRCUIT PIC16F877 MICROCONTROLLER appeared first on PIC Microcontroller.

PIC12F675 RGB LED DRIVE CIRCUIT

$
0
0

We constantly work places which attracts lighting with RGB LEDs that are encountered in a variety of colors created by the transition to the visual feast that may be just a small sample of drivers I share with you… Electronics Projects, PIC12F675 RGB Led Drive Circuit “led projects, microchip projects, microcontroller projects, simple circuit projects,

PIC12F675 RGB LED DRIVE CIRCUIT

We constantly work places which attracts lighting with RGB LEDs that are encountered in a variety of colors created by the transition to the visual feast that may be just a small sample of drivers I share with you are interested. The project is definitely not a product for the purpose of example only write and publish it.

You develop software products can make. Indeed, in the market to make money with this project seriously if possible to offer a product that reason, I find it appropriate.

Project 12f 675 or 683 to be used is written with PIC mosfet transistors plowed an external supply strip with LEDs (12V) to be fed programmatically PWM gradations of color toning is made. (12f675 hardware PWM having is not therefore programmatically PWM is used)

Note: Visuality 675 memory is not sufficient to improve the final version of the project for the 683 I’ve used it and transitions as required is provided in a very pleasant way.

RGB LED DRIVE CIRCUIT TEST

I use strips with RGB LEDs from 20 to 30 meters in length will flow is calculated. Mosfet will use the length can be increased. 237 BC in the accompanying video applications, and I use it a few LEDs for small lampshades easily spreadable.

12V DC 5m colour changing RGB Flexible LED Lighting Strip pack

PIC12F675 RGB LED driver application files:

FILE DOWNLOAD LINK LIST (in TXT format): LINKS-9999.zip

Source: PIC12F675 RGB LED DRIVE CIRCUIT

The post PIC12F675 RGB LED DRIVE CIRCUIT appeared first on PIC Microcontroller.


COMPUTER-CONTROLLED LED SCROLLING MESSAGE DISPLAY TEMPERATURE HUMIDITY ETC.

$
0
0

LED Scrolling Message Display circuit Prepared by: Atila ULUDAĞ – Computer-controlled scrolling marquee application SHT11 DS1302 PIC18F452, MAX485 74HC595 (scan lines) based on the integrated computer software designed to control and c language source code in Visual Basic has… Electronics Projects, Computer-Controlled LED Scrolling Message Display Temperature Humidity etc. “microchip projects, microcontroller projects,

COMPUTER-CONTROLLED LED SCROLLING MESSAGE DISPLAY TEMPERATURE HUMIDITY ETC.

LED Scrolling Message Display circuit Prepared by: Atila ULUDAĞ – Computer-controlled scrolling marquee application SHT11 DS1302 PIC18F452, MAX485 74HC595 (scan lines) based on the integrated computer software designed to control and c language source code in Visual Basic has been prepared by the PIC software.

You can send text marquee circuit via computer date, time, temperature, neb information shows

I do not know if it works but the source code of the application is given of the different projects can be useful in

LED SCROLLING MESSAGE DISPLAY SCHEMATIC

LED SCROLLING MESSAGE DISPLAY SCHEMATIC

LED Scrolling Message circuit schematic visual basic control and code files:

FILE DOWNLOAD LINK LIST (in TXT format): LINKS-9314.zip

Source: COMPUTER-CONTROLLED LED SCROLLING MESSAGE DISPLAY TEMPERATURE HUMIDITY ETC.

The post COMPUTER-CONTROLLED LED SCROLLING MESSAGE DISPLAY TEMPERATURE HUMIDITY ETC. appeared first on PIC Microcontroller.

MICROC LED BLINK EXAMPLE PIC12F675 POLICE LAMP STROBE FLASHING CIRCUIT

$
0
0

In this article microcar hello friends with you in a simple way with the police emergency lights in the form of a burning light I offer project. Microcar, which features extensive use of a compiler. Entirely in C language-based… Electronics Projects, MicroC LED Blink Example PIC12F675 Police Lamp Strobe Flashing Circuit “led projects, microchip projects, microcontroller projects, simple circuit projects,

MICROC LED BLINK EXAMPLE PIC12F675 POLICE LAMP STROBE FLASHING CIRCUIT

In this article microcar hello friends with you in a simple way with the police emergency lights in the form of a burning light I offer project. Microcar, which features extensive use of a compiler. Entirely in C language-based structure. Anyone who knows C can be easily adapted. With little change in the program, such as Hi-tech c compiler can be used in protonc Picbasic.

12F675 can be found very easily in the market and how we can do this work I present to you in an understandable manner. (For anyone who knows the basics of the C language is very easy to understand.)

To work on a small scale with the number of unnecessary pin PICs to be wasted, I believe it is desired to use of PICs.

POLICE LAMP FLASHING CIRCUIT

Police Lamp Strobe Circuit schematic and microc code files:

FILE DOWNLOAD LINK LIST (in TXT format): LINKS-9275.zip

Source: MICROC LED BLINK EXAMPLE PIC12F675 POLICE LAMP STROBE FLASHING CIRCUIT

The post MICROC LED BLINK EXAMPLE PIC12F675 POLICE LAMP STROBE FLASHING CIRCUIT appeared first on PIC Microcontroller.

PIC16F84 LED SHOW CIRCUIT PROTON IDE EXAMPLE

$
0
0

he circuit can be controlled 8 led 4 mode with pic16f84 effect can be gradual or key with choice in commutator welding proton codes and proteus isis simulation file LED Show Circuit Schematic LED Show Proton ide code and… Electronics Projects, PIC16F84 LED Show Circuit Proton ide Example “led projects, microchip projects, microcontroller projects, pic16f84 projects,

PIC16F84 LED SHOW CIRCUIT PROTON IDE EXAMPLE

The circuit can be controlled 8 led 4 mode with pic16f84 effect can be gradual or key with choice in commutator welding proton codes and proteus isis simulation file

LED SHOW CIRCUIT SCHEMATIC

LED SHOW CIRCUIT SCHEMATIC

LED Show Proton ide code and schematic:

FILE DOWNLOAD LINK LIST (in TXT format): LINKS-9168.zip

Source: PIC16F84 LED SHOW CIRCUIT PROTON IDE EXAMPLE

The post PIC16F84 LED SHOW CIRCUIT PROTON IDE EXAMPLE appeared first on PIC Microcontroller.

LEDS EFFECTS CIRCUITS PIC16F628 PIC16F877

$
0
0

There are 3 units LEDs circuit PIC16F877 effects with 33 LEDs and 27 LEDs in one circuit with pic 16F628 pic isis was tested by applying the output from the 330 ohm resistor .470 forget to connect. In addition,… Electronics Projects, LEDs Effects Circuits PIC16F628 PIC16F877 “led projects, microchip projects, microcontroller projects, pic16f628 projects, pic16f877 projects,

LEDS EFFECTS CIRCUITS PIC16F628 PIC16F877

There are 3 units LEDs circuit PIC16F877 effects with 33 LEDs and 27 LEDs in one circuit with pic 16F628 pic isis was tested by applying the output from the 330 ohm resistor .470 forget to connect. In addition, LEDs can be driven further strengthened with transistor output

LED CIRCUIT PIC16F877 33LEDS EFFECTS

LED CIRCUIT PIC16F877 27LEDS EFFECTS

LED CIRCUIT PIC16F628 12LEDS EFFECTS

LEDs Circuits software created with the assembly source. asm, .hex, cod and proteus isis simulation files:

FILE DOWNLOAD LINK LIST (in TXT format): LINKS-8505.zip

Source: LEDS EFFECTS CIRCUITS PIC16F628 PIC16F877

The post LEDS EFFECTS CIRCUITS PIC16F628 PIC16F877 appeared first on PIC Microcontroller.

PICMICRO LED TACHOMETER CIRCUIT

$
0
0

Handmade pretty stylish LED display digital speedometer tacho meters. Source or assembly code pic16f874 PIC16F877 can be done with the circuit and wiring diagrams directly from the preparation given the 33-hole leds pcb layout on a plaque made analog… Electronics Projects, PICmicro LED tachometer Circuit “led projects, microchip projects, microcontroller projects,

PICMICRO LED TACHOMETER CIRCUIT

Handmade pretty stylish LED display digital speedometer tacho meters. Source or assembly code pic16f874 PIC16F877 can be done with the circuit and wiring diagrams directly from the preparation given the 33-hole leds pcb layout on a plaque made

analog instrument into a digital tachometer with analog bargraph LEDs. The meter can measure and display a speed range from 0 rpm to 8000 rpm and higher in 250’er increments. Intermediate values ​​are indicated by a pulse-pause ratio of the next higher LED. This is admittedly a bit of getting used to when it flashes in the view, but can be improved in the software.

LED TACHOMETER CIRCUIT

The LED tachometer is based on the PIC 16F874/877 which can control the LEDs directly with its wealth of I / O pins and makes the overall circuit is therefore very simple.

Was programmed the circuit for a 4-cylinder gasoline engine. The speed is measured directly or via divider resistors at Zündspulenunterbrecher. Configured the PIC on a clock frequency of 20MHz. There were all port pins except PORTA, 0 used as LED pins. The circuit is connected to a total of 4 cables. (+ Ub, GND, CLOCK, backlight).

LED TACHOMETER CIRCUIT

FILE DOWNLOAD LINK LIST (in TXT format): LINKS-7897.zip

Source: PICMICRO LED TACHOMETER CIRCUIT

The post PICMICRO LED TACHOMETER CIRCUIT appeared first on PIC Microcontroller.

Viewing all 387 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>