AVRWARE++ Development Notes 6: 8-way direct I/O port control LED light experiment

Publisher:SereneMelodyLatest update time:2019-07-13 Source: eefocusKeywords:AVRWARE++ Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

         This article is only for beginners, experts please skip it!


    1. Experimental purpose

    Use the IO port of the microcontroller to directly control the LED light and learn how to control the LED light. 


    2. Experimental content

    Write a program to make LEDs 0 to 7 light up from both sides to the middle at an interval of 200ms, and finally all light up for 200ms and then turn off.


    3. Hardware Principle

    The hardware schematic diagram of 8-way direct I/O port controlling LED lights is shown in the figure below. Use a flat cable to connect to terminal P4, then the 0-7 pins of the corresponding port of the microcontroller are connected to the LED0-LED7 pins of terminal P4 (for example, use a flat cable to connect P10 to terminal P4, then the PD0 pin is connected to LED0, the PD1 pin is connected to LED1,... the PD7 pin is connected to LED7). Pins 9 and 10 of terminal P4 are connected to 5V VCC. It can be seen from the figure that the LED is lit at a low level. The corresponding pin of the microcontroller sends a low level, the LED is on, and the corresponding pin of the microcontroller sends a high level, and the LED is off. 

picture  

    4. Experimental reference procedures and annotations

    Change the mapping layer 1_AbstractionLayer_HAL.h file 

//PortD

#define IO_PD_DIR 0b11111111 //This indicates that pins 0-7 are all output

#define IO_PD_OUT 0b11111111 //This specifies that the default initial state of pins 0-7 is high, that is, when powered on,

                                      /LED0-LED7 pins give high level, transistors are not conducting, and the LED lights are off

////////////////////////////////////////////////////////////////////////////////////

//Function macro definition

#define LED0BIT0

#define LED1BIT1

#define LED2BIT2

#define LED3BIT3

#define LED4BIT4

#define LED5BIT5

#define LED6BIT6

#define LED7BIT7

#define LED0_OPENCLRBIT(PORTD,LED0)

#define LED0_SHUTSETBIT(PORTD,LED0)

#define LED0_TURNCPLBIT(PORTD,LED0)

#define LED1_OPENCLRBIT(PORTD,LED1)

#define LED1_SHUTSETBIT(PORTD,LED1)

#define LED1_TURNCPLBIT(PORTD,LED1)

#define LED2_OPENCLRBIT(PORTD,LED2)

#define LED2_SHUTSETBIT(PORTD,LED2)

#define LED2_TURNCPLBIT(PORTD,LED2)

#define LED3_OPENCLRBIT(PORTD,LED3)

#define LED3_SHUTSETBIT(PORTD,LED3)

#define LED3_TURNCPLBIT(PORTD,LED3)

#define LED4_OPENCLRBIT(PORTD,LED4)

#define LED4_SHUTSETBIT(PORTD,LED4)

#define LED4_TURNCPLBIT(PORTD,LED4)

#define LED5_OPENCLRBIT(PORTD,LED5)

#define LED5_SHUTSETBIT(PORTD,LED5)

#define LED5_TURNCPLBIT(PORTD,LED5)

#define LED6_OPENCLRBIT(PORTD,LED6)

#define LED6_SHUTSETBIT(PORTD,LED6)

#define LED6_TURNCPLBIT(PORTD,LED6)

#define LED7_OPENCLRBIT(PORTD,LED7)

#define LED7_SHUTSETBIT(PORTD,LED7)

#define LED7_TURNCPLBIT(PORTD,LED7)

#define ALL_LED_OPEN //Open all LEDs LED0_OPEN;LED1_OPEN;LED2_OPEN;LED3_OPEN;LED4_OPEN;LED5_OPEN;LED6_OPEN;LED7_OPEN

#define ALL_LED_SHUT //Turn off all LEDs LED0_SHUT;LED1_SHUT;LED2_SHUT;LED3_SHUT;LED4_SHUT;LED5_SHUT;LED6_SHUT;LED7_SHUT


    Modify the logic layer 0_logiclayer_main.c file

//Main program

int main(void)

{

    //Target initialization, this function will automatically initialize the corresponding peripheral files

    TARGET_Init();

    //Background main loop

    while(1)

    {

        //Complete your own project logic here

        LED0_OPEN;

        LED7_OPEN;

        TARGET_Delayms(200,1);

        LED0_SHUT;

        LED7_SHUT;

        TARGET_Delayms(200,1);

        LED1_OPEN;

        LED6_OPEN;

        TARGET_Delayms(200,1);

        LED1_SHUT;

        LED6_SHUT;

        TARGET_Delayms(200,1);

        LED2_OPEN;

        LED5_OPEN;

        TARGET_Delayms(200,1);

        LED2_SHUT;

        LED5_SHUT;

        TARGET_Delayms(200,1);

        LED3_OPEN;

        LED4_OPEN;

        TARGET_Delayms(200,1);

        LED3_SHUT;

        LED4_SHUT;

        TARGET_Delayms(200,1);

        ALL_LED_OPEN;

        TARGET_Delayms(200,1);

        ALL_LED_SHUT;

        TARGET_Delayms(200,1);

        // Feed the dog statement, most projects should not remove it

        #if WDT_MODE!=0

            TARGET_WatchDogReset();

        #endif

    }

    return 0; // never executed

}



Keywords:AVRWARE++ Reference address:AVRWARE++ Development Notes 6: 8-way direct I/O port control LED light experiment

Previous article:AVRWARE++ Development Notes 7: 74HC595 Serial Control LED Light Experiment
Next article:AVRWARE++ Development Notes 5: Buzzer Drive Experiment

Recommended ReadingLatest update time:2024-11-23 15:20

MINI2440i2c driver learning 2
In the test function, there is a function eeprom_open("/dev/i2c/0", 0x50, EEPROM_TYPE_8BIT_ADDR, &e); the call inside is as follows int eeprom_open(char *dev_fqn, int addr, int type, struct eeprom* e) {  int funcs, fd, r;  e- fd = e- addr = 0;  e- dev = 0;    fd = open(dev_fqn, O_RDWR);  if(fd = 0)  {   fprintf(stde
[Microcontroller]
51 MCU——I2C bus EEPROM
We can save the data in EEPROM so that the data will not be lost when the power is off. Commonly used serial bus protocols: Currently, the commonly used serial buses for data transmission between microcomputers and peripherals are mainly I2C bus, SPI bus and SCI bus. I2C bus: Communicates in a synchronous serial 2
[Microcontroller]
51 MCU——I2C bus EEPROM
51 MCU i2c multi-byte read and write 24c02
It can be downloaded using Keil's compilation environment, but the entry address is shown in the yellow line below. If single-step execution (F11) or full-speed run (F5) is performed, the program always stays at the original position (0x1FFF4252). If the PC pointer value and SP value are forced to be changed to 0x8000
[Microcontroller]
51 MCU i2c multi-byte read and write 24c02
Pushing machine learning to the edge: i.MX 8M Plus in-depth analysis
Research in artificial intelligence (AI) has made amazing progress, and the uses of computers have continued to expand. Machines can perform certain tasks faster and more accurately than humans. A good example is the ILSVRC image classification competition, which uses a type of artificial intelligence based on machine
[Internet of Things]
Pushing machine learning to the edge: i.MX 8M Plus in-depth analysis
51 MCU I2C 24c02 1-99 seconds cycle timer
51 single-chip microcomputer, I2C 24c02 1-99 seconds cycle timer simulation circuit. The program source code HEX file   single-chip source program is as follows: #include "reg52.h"                          #include "i2c.h"         #ifndef fly #define uchar unsigned char #endif #ifndef uint #define uint unsigne
[Microcontroller]
51 MCU I2C 24c02 1-99 seconds cycle timer
PIC microcontroller I2C bus
Hello everyone, through the previous study, we have learned and become familiar with the use and learning methods of ICD2 simulation burner and enhanced PIC experiment board, and learned how to use single chip microcomputer to control LED, relay, buzzer, button, digital tube, RS232 serial port, stepper motor, temperat
[Microcontroller]
PIC microcontroller I2C bus
51 MCU I/O port read and write operations
MCS-51 microcontrollers usually have four 8-bit I/O ports. The data written to each port is written into the latch of the corresponding port, but there are two ways to read each port: read the latch and read the pin. 1 Read-Modify-Write Operation     Pn (referring to P0, P1, P2, P3) is a special identifier in 51 assem
[Microcontroller]
51 MCU I/O port read and write operations
linux-2.6.32 porting I2C-EEPROM driver on mini2440 development board
1 Configure I2C driver in the kernel Linux-2.6.32.2 provides a complete driver for the I2C interface of S2C2440, so we only need to configure it in the kernel to use it. Execute: make menuconfig in the kernel source code directory to enter the kernel configuration main menu, and select the following submenus
[Microcontroller]
linux-2.6.32 porting I2C-EEPROM driver on mini2440 development board
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号