Smarthome Remote Control System Producer

KinCony Electronic —- makes our life more beautiful quality more excellent and life more intelligent

Archive for July, 2010

8.5. Experiment with 93C46 Serial EEPROM

Posted by admin July - 27 - 2010 - Tuesday ADD COMMENTS

The 93C46 provides 1024 bits of serial electrically-erasable programmable read-only memory (EEPROM) organized as 64 words of 16 bits each. The device is opti-mized for use in many industrial and commercial applications where low-power and low-voltage operation are essential. The 93C46 is available in space-saving 8-lead PDIP, 8-lead JEDEC SOIC, and 8-lead TSSOP packages.

The 93C46 is enabled through the Chip Select pin (CS) and accessed via a three-wire serial interface consisting of Data Input (DI), Data Output (DO), and Shift Clock (SK). Upon receiving a Read instruction at DI, the address is decoded and the data is clocked out serially on the data output DO pin. The write cycle is completely self-timed and no separate erase cycle is required before write. The write cycle is only enabled when the part is in the erase/write enable state. When CS is brought high following the initiation of a write cycle, the DO pin outputs the ready/busy status of the part.

CS: Chip Select

SK: Serial Data Clock

DI: Serial Data Input

DO: Serial Data Output

GND: Ground

VCC: Power Supply

NC: No Connect

Instruction Set for the AT93C46E:

Instruction SB Op Code Address Comments
READ 1 10 A5 − A0 Reads data stored in memory, at specified address
EWEN 1 00 11XXXX Write enable must precede all programming modes
ERASE 1 11 A5 − A0 Erase memory location An − A0
WRITE 1 01 A5 − A0 Writes memory location An − A0
ERAL 1 00 10XXXX Erases all memory locations. Valid only at VCC = 4.5V to 5.5V
WRAL 1 00 01XXXX Writes all memory locations. Valid only at VCC = 4.5V to 5.5V
EWDS 1 00 00XXXX Disables all programming instructions

Program Function

The experiment illustrates the I2C communication between MCU and 24C01 EEPROM. Data 0×55 and 0xAA are written to EEPROM at memory address 0×02 and 0×03. The data read from EEPROM will be displayed on LED display. By default, the address to be read is 0×02, user can change the address.

Toggle on the function select to ‘93C**’ before this experiment.

Schematic Diagram

Program Flow Chart

8.4. Experiment with 24C01 EEPROM

Posted by admin July - 27 - 2010 - Tuesday ADD COMMENTS

AT24C01 Overview

The AT24C01 provides 1024 bits of serial electrically erasable and programmable read-only memory (EEPROM) organized as 128 words of 8 bits each. The device is optimized for use in many industrial and commercial applications where low-power and low-voltage operation are essential. The AT24C01 is available in space-saving 8-lead PDIP, 8-lead JEDEC SOIC, 8-lead Ultra Thin Mini-MAP (MLP 2×3), 5-lead SOT23 , 8-lead TSSOP, and 8-ball dBGA2 packages and is accessed via a Two-wire serial interface. In addition, the entire family is available in 2.7V (2.7V to 5.5V) and 1.8V (1.8V to 5.5V) versions.

SCL: The SCL input is used to positive edge clock data into each EEPROM device and negative edge clock data out of each device.

SDA: The SDA pin is bidirectional for serial data transfer. This pin is open-drain driven and may be wire-ORed with any number of other open-drain or open-collector devices.

A2, A1, A0: The A2, A1 and A0 pins are device address inputs that are hard wired for the AT24C01.

WP: The AT24C01 has a Write Protect pin that provides hardware data protection. The Write Protect pin allows normal Read/Write operations when connected to ground (GND). When the Write Protect pin is connected to VCC, the write protection feature is enabled and operates as shown in Table 2.

VCC:Power supply, +5V.

VSS:Ground.

Program Function

The experiment illustrates the I2C communication between MCU and 24C01 EEPROM. Data 0×55 and 0xAA are written to EEPROM at memory address 0×01 and 0×02. The data read from EEPROM will be displayed on LED display. By default, the address to be read is 0×02, user can change the address.

Toggle on the function select to ‘24D**’ before this experiment.

Schematic Diagram

Program Flow Chart

8.3. Experiment with 1-Wire Digital Thermometer DS18B20

Posted by admin July - 27 - 2010 - Tuesday ADD COMMENTS

The DS18B20 Digital Thermometer provides 9 to 12–bit centigrade temperature measurements and has an alarm function with nonvolatile user-programmable upper and lower trigger points. The DS18B20 communicates over a 1-Wire bus that by definition requires only one data line (and ground) for communication with a central microprocessor. It has an operating temperature range of –55°C to +125°C and is accurate to ±0.5 °C over the range of –10°C to +85°C. In addition, the DS18B20 can derive power directly from the data line (‘parasite power’), eliminating the need for an external power supply.

Each DS18B20 has a unique 64-bit serial code, which allows multiple DS18B20s to function on the same 1–wire bus; thus, it is simple to use one microprocessor to control many DS18B20s distributed over a large area. Applications that can benefit from this feature include HVAC environmental controls, temperature monitoring systems inside buildings, equipment or machinery, and process monitoring and control systems.

Features:

Unique 1-Wire interface requires only one port pin for communication

Each device has a unique 64-bit serial code stored in an onboard ROM

Multidrop capability simplifies distributed temperature sensing applications

Requires no external components

Can be powered from data line. Power supply range is 3.0V to 5.5V

Measures temperatures from –55°C to +125°C (–67°F to +257°F)

±0.5 °C accuracy from –10°C to +85°C

Thermometer resolution is user-selectable from 9 to 12 bits

Converts temperature to 12-bit digital word in 750ms (max.)

User-definable nonvolatile (NV) alarm settings

Alarm search command identifies and addresses devices whose temperature is outside of programmed limits (temperature alarm condition)

Available in 8-pin SO (150mil), 8-pin SOP, and 3-pin TO-92 packages

Software compatible with the DS1822

Applications include thermostatic controls, industrial systems, consumer products, thermometers, or any thermally sensitive system

Software and Hardware Design with DS18B20

This experiment illustrates the software and hardware interface between DS18B20 and MCU. MCU reads temperature from DS18B20, and display the result on LED display.

Plug in the DS18B20 chip into the socket, and toggle on the function select to ‘18B20’ before using.

Schematic Diagram

Program Flow Chart

8.2. Experiment with Stepping Motor

Posted by admin July - 27 - 2010 - Tuesday ADD COMMENTS

Recently, loop pulse distributor is used to control the stepping motor. The loop pulse distributor can be composed by discrete devices, controlled by software, or dedicated integrated circuit.

Generally, a full stepping motor controlling system consists of controller, driver and motor, like the below diagram.

controller driver motor
Excitation Mode of Stepping Motor

Usually, there are 3 excitation modes: 1 phase excitation, 2 phase excitation and 1-2 phase excitation. 1 phase mode is the easiest, but generates least torque. 2 phase mode generates better torque. 1-2 phase mode is a half-step mode, that is, the rotation angle is half the former 2 modes.

1 phase excitation
number of steps A B /A /B
1 1 0 0 0
2 0 1 0 0
3 0 0 1 0
4 0 0 0 1
5 1 0 0 0
6 0 1 0 0
7 0 0 1 0
8 0 0 0 1
2 phase excitation
number of steps A B /A /B
1 1 1 0 0
2 0 1 1 0
3 0 0 1 1
4 1 0 0 1
5 1 1 0 0
6 0 1 1 0
7 0 0 1 1
8 1 0 0 1
1-2 phase excitation
number of steps A B /A /B
1 1 0 0 0
2 1 1 0 0
3 0 1 0 0
4 0 1 1 0
5 0 0 1 0
6 0 0 1 1
7 0 0 0 1
8 1 0 0 1

Stepping Motor Driving Circuit

The small stepping motor used in this section has no special requirements on driving voltage or current. Improvement must be taken when stepping motor is used in industrial design. The below picture shows the general driving circuit.

Most often, more than 1 driver is needed in practical applications. The above circuit requires many components, and space on PCB boards. Integrated circuits like ULN2003, ULN2803 are a better solution for multiple drivers.

K8MDP contains ULN2003, which is high voltage, high current darlington arrays each containing seven open collector darlington pairs with common emitters. Each channel rated at 500mA and can withstand peak currents of 600mA. Suppression diodes are included for inductive load driving and the inputs are pinned opposite the outputs to simplify board layout. It is useful for driving a wide range of loads including solenoids, relays DC motors, LED displays filament lamps, thermal print heads and high power buffers.

Schematic diagram of ULN2003 is shown at below pictures.

Below shows the classic application circuit with ULN2003.

Software Design for Stepping Motor

Functions: motor will rotate clockwise at system power on, it rotates counter-clockwise when key SW20 is depressed.

Loop pulse table for clockwise rotation:

number of steps P00 P01 P02 P03
A B /A /B
1 1 1 0 0
2 0 1 1 0
3 0 0 1 1
4 1 0 0 1

Loop pulse table for counter-clockwise rotation:

number of steps P00 P01 P02 P03
A B /A /B
1 1 1 0 0
2 1 0 0 1
3 0 0 1 1
4 0 1 1 0

Schematic Diagram

Program Flow Chart

8.1. Experiment with Matrix Key8051 guide

Posted by admin July - 27 - 2010 - Tuesday ADD COMMENTS

Introduction

The 4*4 matrix key, also called key array, consists of 4 I/O rows and 4 I/O columns. Every key cross over a junction of row and column. In this way, I/O port can be used effectively.

Principle of Matrix Key

The most common matrix key is like the below picture. Composed by 16 keys, 1 I/O port can be used to implement the matrix.

The circuit of matrix key.

When no key is depressed, P1.0 ~ P1.3 and P1.4 ~ P1.7 are open-circuit. When any key is depressed, those I/O lines which are connected with the key will be short-cut.

Method to recognize the status of keys:

Step 1, set column P1.4 ~ P1.7 to be input, and set row P1.0 ~ P1.3 to be low level. Then read the status of column P1.4 ~ P1.7, if there is one column low level, there must be a key depressed. Now move on to Step 2 to locate the key.

Step 2, set row P1.0 ~ P1.3 to be low level in turn, and read from column P1.4 ~ P1.7. If a column is low level, the depressed key is then located.

By the result of 2 steps, the depressed key is found. Remember, one pressing of the key only causes one action which calls a key processing function, therefore, key processing function must be invoked after the key is released.

Example on Matrix Key Design

The example illustrates how to program the matrix key in the K8MDP. When 1 key is pressed, the key number will be displayed on the LED display, from 0 to F.

Below is the schematic diagram.

Row P1.0 ~ P1.3 are output lines. Column P1.4 ~ P1.7 are input lines. At the beginning, row P1.0 ~ P1.3 output low level. Then read the column P1.4 ~ P1.7. If they are all high level, there must be no key depressed. If one of the columns is low level, a certain period of time delay is needed to get rid of the impact from key pressing noise. After the delay, if that column is still low level. Then it is certain that there is one key depressed.

To know which key is depressed, we can scan the whole matrix. Set row P1.0 ~ P1.3 to be 0111, 1011, 1101, 1110 in turn, at the same time, read the column P1.4 ~ P1.7. If the value read from P1.4 ~ P1.7 is the 1111, then there is no key depressed, otherwise, the value is the key number.

Now let’s take the S5 key for example. When we pressed S5, and scan row P1.0 ~ P1.3, we can read 1011 from P1.4 ~ P1.7. 1011 is 0x0B in octal. So, jumper to S5 key processing subroutine to react the S5 key action.

7.7. Experiment with Serial Port

Posted by admin July - 27 - 2010 - Tuesday ADD COMMENTS

Till now all the experiments are related to I/O port. To connect the MCU to PC, serial port is a must to learn.

This experiment shows how the MCU receives data from PC and then display on LED displays.

The Fundamental of Serial Port

As we know, 8051 MCU is equipped with a full duplex serial communication port. However, computer’s serial port works on RS-232 level, while MCU’s is TTL level. Thus, there must be a level converter between RS-232 and TTL. Here we use MAX232 chip to convert the two types of levels.

The MAX232 device consists of two line drivers, two line receivers, and a dual charge-pump circuit with ±15-kV ESD protection pin to pin (serial-port connection pins, including GND). The device meets the requirements of TIA/EIA-232-F and provides the electrical interface between an asynchronous communication controller and the serial-port connector. The charge pump and four small external capacitors allow operation from a single 5-V supply. The device operates at data signaling rates up to 120 kbit/s and a maximum of 30-V/µs driver output slew rate.

The simplest way to use MAX232 is like the below diagram.

To read the data from MCU on PC, a windows software is needed, the SComAssistant V2.1.

In SComAssistant, parameters like serial port number, Baudrate, check-sum can all be set. It is very important to make sure the settings between PC and MCU are the same.

Circuit Design

Software Design

#include “reg51.h” //include the 8051 register definition header file

//common-anode display code table

unsigned char code tab[]={0xc0,0xf9,0xa4,0xb0,0×99,0×92,0×82,0xf8,0×80,0×90};

unsigned char dat; //define the global variable

void Init_Com(void) //initialize the serial port

{

TMOD = 0×20;

PCON = 0×00;

SCON = 0×50;

TH1 = 0xFd; //baud rate: 9600bps

TL1 = 0xFd;

TR1 = 1;

}

void delay(void) //LED display delay

{

int k;

for(k=0;k<600;k++);

}

serial()interrupt 4 using 1 //interrupt service routine

{

if(RI)

RI=0; //clear the receiving flag

dat=SBUF; //receive data

}

void display(int k) //LED display function

{

P2=0xfe; //digital select

P0=tab[k/1000]; //display the 4th number

delay(); //delay

P2=0xfd; //digital select

P0=tab[k%1000/100]; //display the 3rd number

delay(); //delay

P2=0xfb; //digital select

P0=tab[k%100/10]; //display the 2nd number

delay(); //delay

P2=0xf7; //digital select

P0=tab[k%10]; //display the 1st number

delay(); //delay

P2=0xff; //digital select

}

void main() //main function

{

P2=0xff; //initialize I/O port

P0=0xff; //initialize I/O port

EA=1; //enable all interrupts

ES=1; //enable serial interrupt

Init_Com(); //invoke serial port initialization

while(1) //loop

{

display(dat); //invoke display function

}

}

7.6. Experiment with LED Display

Posted by admin July - 27 - 2010 - Tuesday ADD COMMENTS

In normal system, LED and LCD are common output interface. LED display can be found in various devices and machines. It is a cheap, high-luminance, versatile display.

This experiment discusses the basic operation on LED. It’ll show you how to display 0 to 9 in the 1st LED display.

The Fundamentals of LED Display

LED display is composed by 8 light emitting diodes, among which 7 diodes form the numerical number 8, and 1 diode represent the dot (decimal point).

According to the driving mode, LED can be divided to 2 types, common-anode and common-cathode. A common-anode LED display is that the one with 8 LEDs’ anodes connecting together. A common-cathode LED display is that the one with 8 LEDs’ cathodes connecting together. See the below diagram.

To make a LED display show the numerical number, we need to light on and off certain segments (diodes). For example, to display number 5, segment A, C, D, F, G should be light on. Thus expect for P0.1, P0.4, P0.7, the rest P0.0, P0.2, P0.3, P0.5, P0.6 should all be set to 1, high level.

Segment DP G F E D C B A code
Pin P0.7 P0.6 P0.5 P0.4 P0.3 P0.2 P0.1 P0.0
“5” 0 1 1 0 1 1 0 1 0x6d

Likewise, we can list the table of display code for 0 to 9. Below is the table for common-anode and common-cathode.

Numeric number 0 1 2 3 4 5 6 7 8 9
common-cathode 0x3F 0×06 0x5B 0x4F 0×66 0x6D 0x7D 0×07 0x7F 0x6F
common-anode 0xC0 0xF9 0xA4 0xB0 0×99 0×92 0×82 0xF8 0×80 0×90

Circuit Design

Software Design

01 #include <reg51.h>

02

03 unsigned char code Tab[]={ 0xC0,0xF9,0xA4,0xB0,0×99,0×92,0×82,0xF8,

04 0×80,0×90,0×88,0×83,0xC6,0xA1,0×86,0x8E};

05 sbit S1 = P2^0;

06

07 void Delay()

08 {

09 unsigned char i,j;

10 for(i=0;i<255;i++)

11    for(j=0;j<255;j++);

12 }

13

14 void main()

15 {

16 unsigned char i = 0;

17 S1 = 0;

18  while(1)

19  {

20    P0= Tab[i];

21    Delay();

22    i++;

23    if(i>9) i =0;

24  }

25 }

Program Notes

Line 1: include the 8051 register definition header file

Line 3-4: define common-anode display code table

Line 5: sbit define common control S1

Line 7-12: delay function

Line 14: main function

Line 16: define local variable i for counting

Line 17: give power to LED S1

Line 18: loop

Line 20: output display code to P0

Line 21: invoke delay function

Line 22: increment i

Line 23: limit i to be in the range from 0 to 9

Program for Multiple LED displays

The above experiment shows you how to display a single LED, but how do we make multiple LEDs display? Time sharing is a technique people often used to display more than 1 LED display. See the below codes.

01 #include <reg51.h>

02

03 unsigned char code Tab[]={ 0xC0,0xF9,0xA4,0xB0,0×99,0×92,0×82,0xF8,

04 0×80,0×90,0×88,0×83,0xC6,0xA1,0×86,0x8E};

05 sbit S1 = P2^0;

06 sbit S2 = P2^1;

07 sbit S3 = P2^2;

08 sbit S4 = P2^3;

09

10 void Delay()

11 {

12 unsigned char i;

13 for(i=0;i<255;i++);

14 }

15

16 void main()

17 {

18  while(1)

19  {

20    P0= Tab[1];

21 S1 = 0; //turn on S1

22    Delay();

23 S1 = 1; //turn off S1

24

25    P0= Tab[2];

26 S2 = 0; //turn on S2

27    Delay();

28 S2 = 1; //turn off S2

29

30    P0= Tab[3];

31 S3 = 0; //turn on S3

32    Delay();

33 S3 = 1; //turn off S3

34

35    P0= Tab[4];

36 S4 = 0; //turn on S4

37    Delay();

38 S4 = 1; //turn off S4

39  }

40 }

From line 20 to 38, we can see the whole time sharing procedure. Firstly, display code is output on data bus P0, then turn on a LED, delay a certain time, and then turn off it. Repeat this until 4 LED is all turn on for once. Then restart the procedure again. To make the most of human-being’s retentivity of vision, care should be taken with these points. To avoid the LED flashing, delay time should not be too long. To have equal luminance, each delay time must be the same. To increase the luminance, delay time can be shortened. If there are double images on LED, LED should be turn on and then turn off.

7.5. Experiment with Relay

Posted by admin July - 27 - 2010 - Tuesday ADD COMMENTS

In modern controlling system, electronic circuit controlling electrical circuit is very common. Relay plays two roles in these systems. 1) it enables the electronic circuit to control the device or component (e.g., motor, electromagnet, lamp, etc.) electrical circuit. 2) it isolates the electronic circuit from the electrical circuit, for the sake of safety in both system and human being. Relay is therefore a bridge between electronic circuit and electrical circuit.

This experiment shows how to control the relay to open and close.

The Fundamentals of Relay

Relay is a electronic controlling device, which has the controlling system (so called input circuit), and controlled system (so called output circuit). Mostly working in automatic controlling circuit, it use low current to control high current. It functions as an adjustment, safety protection, transferring circuit, etc.

In most cases, a relay is an electromagnet. It consists of a coil of wire surrounding a soft iron core, an iron yoke. When an electric current is passed through the coil, the resulting magnetic field attracts the armature, and the consequent movement of the movable contact or contacts either makes or breaks a connection with a fixed contact. If the set of contacts was closed when the relay was de-energised, then the movement opens the contacts and breaks the connection, and vice versa if the contacts were open.

There are many types of relay, latching relay, polarized relay, reed relay, solid-state relay, etc. The relay used in the development board looks like the below picture.

Relay is also an inductance device. MCU I/O port should not be used to control relay directly. Normally, a PNP transistor is used to open and close the relay.

Circuit Design

Software Design

01 #include <reg51.h>

02

03 sbit RELAY = P1^3;

04

05 void Delay()

06 {

07 unsigned char i,j;

08 for(i=0;i<255;i++)

09 for(j=0;j<255;j++);

10 }

11

12 void main()

13 {

14 while(1)

15 {

16 RELAY = 0;

17 Delay();

18 RELAY = 1;

19 Delay();

20 }

21 }

Program Notes

Line 1: include the 8051 register definition header file

Line 3: sbit define relay to P1.3

Line 5-10: delay function, the delay time depends on MCU clock

Line 7: define2 unsigned char variable i, j

Line 8-9: loop by i and j self-increment

Line 12-21: main function

Line 14: the main loop, while loop

Line 16: open the relay

Line 17: invoke the delay function

Line 18: close the relay

Line 19: invoke the delay function

7.4. Experiment with Beeper

Posted by admin July - 26 - 2010 - Monday ADD COMMENTS

Except for display components in a MCU system, sound generators are also used. The most common sound generator is beeper, also called buzzer, which will generate different frequency sound at different frequency square wave.

This experiment introduces the user how to make a beeper generate sound.

The Fundamentals of Beeper

Compared with speaker, beeper is very easy to control. Only certain current is needed to drive the beeper, make it generate sound. Therefore, it is basically the same to control a LED or a beeper.

Circuit Design

Because beeper has inductance, it’s not recommended to control it by I/O pin directly. Transistor and diode can be used to isolate the beeper from I/O. In this experiment, we only use transistor.

The PNP transistor in below diagram controls the beeper. When MCU P3.6 is set to low level, the beeper will sound.

Software Design

01 #include <reg51.h>

02

03 sbit BUZZER=P3^7;

04

05 void main(void)

06 {

07 BUZZER = 0;

08 while(1);

09 }

Program Notes

Line 1: include the 8051 register definition header file

Line 3: sbit define beeper to P3.7

Line 5-9: main function

Line 7: set P3.7 to output low level, making the beeper sound

Line 8: loop

7.2. Experiment with Flowing LEDs

Posted by admin July - 26 - 2010 - Monday ADD COMMENTS

In the last experiment, it shows basic LED flashing experiment. In daily life, flowing LEDs are often seen in LED ads. In this experiment, the principle and programming of flowing LEDs is discussed.

The Fundamentals of Flowing LEDs

To light up LEDs as a flowing water, 8 LEDs are used in the development board. At any time, one of 8 LEDs lights up. It starts up with the LED1 on, and then LED2, and goes on. When LED8 is on, the flowing LED is finished in this turn. LED1 lights up again in the next. See the below table.

LED Led1 Led2 Led3 Led4 Led5 Led6 Led7 Led8
I/O pin P1.0 P1.1 P1.2 P1.3 P1.4 P1.5 P1.6 P1.7
Reset status
status 1
status 2
status 3
status 4
status 5
status 6
status 7
status 8

Circuit Design

Software Design

01 #include <reg51.h>

02

03 sbit LED1 = P1^0;

04 sbit LED2 = P1^1;

05 sbit LED3 = P1^2;

06 sbit LED4 = P1^3;

07 sbit LED5 = P1^4;

08 sbit LED6 = P1^5;

09 sbit LED7 = P1^6;

10 sbit LED8 = P1^7;

11

12 void Delay()

13 {

15 unsigned char i,j;

16 for(i=0;i<255;i++)

17    for(j=0;j<255;j++);

18 }

19

20 void main()

21 {

22  while(1)

23  {

24    P1 = 0xff;

25    LED1 = 0;

26    Delay();

27    LED2 = 0;

28    LED1 = 1;

29    Delay();

30    LED3 = 0;

31    LED2 = 1;

32    Delay();

33    LED4 = 0;

34    LED3 = 1;

35    Delay();

36    LED5 = 0;

37    LED4 = 1;

38    Delay();

39    LED6 = 0;

40    LED5 = 1;

41    Delay();

42    LED7 = 0;

43    LED6 = 1;

44    Delay();

45    LED8 = 0;

46    LED7 = 1;

47    Delay();

48  }

49 }

Program Notes

Line 1: include the 8051 register definition header file

Line 3-10: bit define LED1 ~ LED8 to P1.0 ~ P1.7

Line 12-18: delay function, the delay time depends on the MCU clock

Line 20: main function

Line 24: set P1 port all to be 1, lights all LEDs off

Line 25: light LED1 on

Line 26: invoke the delay function

Line 27: light LED2 on

Line 28: light LED1 off

Line 29: invoke the delay function

Line 30-47: light on or off LEDs

A Better Program

Till now, the flowing LEDs is done. But there’s a better way to meet the need. See the following codes.

#include <reg51.h>

void Delay()

{

unsigned char i,j;

for(i=0;i<255;i++)

for(j=0;j<255;j++);

}

void main()

{

unsigned char i;

unsigned char temp;

P1 = 0xff; //set all P1.x to 1, light all LEDs off

while(1)

{

temp = 0×01; //assign initial value to temp, with 1 bit set

for(i = 0; i < 8; i++)

{

P1 = ~temp;  //logic not temp

Delay();  //invoke delay function

temp = temp << 1; //left move temp variable by 1 bit

}

}

}

The above codes implement the same function. The difference is that we take 8 LEDs as a whole. Assign a variable to P1 to set P1.0 ~ P1.7 to different status.

i=0 i=1 i=2 i=3 i=4 i=5 i=6 i=7
temp 0×01 0×02 0×04 0×08 0×10 0×20 0×40 0×80
~temp 0xfe 0xfd 0xfb 0xf7 0xef 0xdf 0xbf 0x7f

Universal Programmer | Gang Programmer | Device Programmer | ISP Programmer | Eeprom Programmer | IC Programmer
Copyright © 2003-2012 Programmerkit.com All Rights Reserved.
Add:Rm 852,4F,Zhejiang Shidai Electronics Market,Dengyun Rd 428, Hangzhou, Zhejiang, China. P.C.:310011