Design of reading data from 24C02 to digital tube display based on PIC microcontroller

Publisher:tmgouziLatest update time:2020-01-16 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The test function is to reset the microcontroller once, automatically read the data from 24C02 to the digital tube display, then add 1 to the value and write it into 24C02. Finally, the data in the digital tube is the number of times the machine is turned on, which has certain practical significance.


; The 24C02 used in this circuit is from ATMEL, or not from this manufacturer, so the programming time may be different

;The DELAY time of this program must be adjusted

The purpose of this practice is to make everyone more familiar with the timing of I2C communication, familiar with the reading and writing of 24CXX, and how to use software to simulate I2C communication.

;Hardware connection:

Design of reading data from 24C02 to digital tube display based on PIC microcontroller
 

;1.24CXX's SDA connects to 877A's RB5 port, SCLK connects to 877A's RB4 port, WP connects to ground, A0, A1, A2 connect to ground

;2. Experiment: For this experiment, the 93CXX series chip on the MCD-DEMO experimental board must be removed first. During the experiment, do not press the buttons that are also connected to the RB port to avoid affecting the communication timing.

;3. The DIP switches S4 and S5 on the experimental board should be turned ON, and other DIP switches can be turned off.

;The program list is as follows:

;************************************

LIST P=16F877A, R=DEC

include ”P16F877A.inc“

;***********************************

__CONFIG _DEBUG_OFF&_CP_OFF&_WRT_HALF&_CPD_OFF&_LVP_OFF&_BODEN_OFF&_PWRTE_ON&_WDT_OFF&_XT_OSC;

;**************************************** Define the lookup table offset

#define SDA PORTB,5

#define SCLK PORTB,4

;*********************

COUNT EQU 20H

ADDR EQU 21H

DAT EQU 23H

TEMP EQU 24H

;**********************

ORG 000H

NOP ; Place a no-operation instruction required by ICD

GOTO MAIN

ORG 004H

RETURN

ORG 0008H

;******************************************************

TABLE

ADDWF PCL, 1; address offset plus current PC value

RETLW 0C0H ;0

RETLW 0F9H ;1

RETLW 0A4H ;2

RETLW 0B0H ;3

RETLW 99H ;4

RETLW 92H ;5

RETLW 82H ;6

RETLW 0F8H ;7

RETLW 80H ;8

RETLW 98H ;9

RETLW 00H ;A

RETLW 00H ;B

RETLW 00H ;C

RETLW 00H ;D

RETLW 00H ;E

RETLW 00H ;F

;*******************************************************

MAIN

MOVLW 0FFH

MOVWF PORTC; All digital tubes are turned off first

MOVLW 0FFH

MOVWF PORTA

MOVLW 0FFH

MOVWF PORTB; SDT, SCLK are both high

BSF STATUS, RP0; define RA port, RC port, RB port are all output

MOVLW 07H

MOVWF  ADC ON1; Set all RA ports to normal digital IO ports

CLRW

MOVWF TRISB ;

MOVWF TRISA

MOVWF TRISC

MOVWF OPTI ON_REG ; Enable the internal weak pull-up of RB port

BCF STATUS,RP0

CLRW ; Address 00H

CALL RD24 ; read address

MOVWF DAT ; the read value is sent to F1

SUBLW .9; If the read value is greater than 9, F1 is sent to 0, starting from 0 (because the 1-digit digital tube can only display 0-9)

BC TT2; C=0, transfer to TT2

TT1

CLRF DAT

TT2

MOVFW DAT

CALL TABLE ; Get the display segment code

MOVWF PORTC ;segment code sent to port C

BCF PORTA, 1; light up the first digital tube

INCF DAT, 1; Each time the power is turned on, the value stored in the 00H address of 24CXX is increased by 1

CLRW ; Address 00H

CALL WT24 ; write 24CXX

GOTO $

;****************************

RD24

MOVWF ADDR; The address is temporarily stored in F4

CALL START24 ; Start I2C

MOVLW 0A0H

CALL SUBS; write device address 1010000 + last bit 0 write operation

MOVFW ADDR ; load address

CALL SUBS ; write address

CALL START24 ; resend the start signal

MOVLW 0A1H; write device address 1010000 + last bit 1 read operation

CALL SUBS

BSF STATUS ,RP0

BSF TRISB, 5; Set SDA pin as input, ready to read

BCF STATUS ,RP0

MOVLW 08H; read 8 bits of data

MOVWF COUNT

RD000

NOP

NOP

NOP

BSF SCLK ; read data

NOP

BSF STATUS,C

BTFSS SDA

BCF STATUS,C

RLF TEMP ,1

BCF SCLK

DECFSZ COUNT, 1; loop to read 8 bits

GOTO RD000

BSF STATUS ,RP0

BCF TRISB, 5; restore SDA pin to output

BCF STATUS ,RP0

BSF SDA

CALL DELAY2

BSF SCLK

CALL DELAY2

BCF SCLK; Response completed, SDA set to 1

CALL STOP ; send stop signal

MOVFW TEMP ; send the read data to W

RETURN

;******************************Write 24C02 program

WT24 MOVWF ADDR; first store the address temporarily in F4

CALL START24 ;Start condition

MOVLW 0A0H

CALL SUBS; write device address 1010000 + last bit 0 write operation

MOVFW ADDR ; load address

CALL SUBS ; write address

MOVFW DAT ; load data

CALL SUBS ; write data

CALL STOP ;Stop signal

RETURN

START24

;Start condition

BSF SDA

BSF SCLK

CALL DELAY2

BCF SDA

CALL DELAY2

BCF SCLK

RETURN

STOP

BCF SDA ; Stop condition

NOP

NOP

BSF SCLK

CALL DELAY2

BSF SDA

RETURN

SUBS ; write data

MOVWF TEMP ; store the data to be written in F2

MOVLW 08H

MOVWF COUNT ; write 8-bit data

SH01

RLF TEMP ,1

BSF SDA

BTFSS STATUS ,C

BCF SDA

NOP

BSF SCLK

CALL DELAY2

BCF SCLK

DECFSZ COUNT, 1; loop to write 8 bits

GOTO SH01

BSF SDA

NOP

NOP

BSF SCLK

BSF STATUS,RP0

BSF TRISB ,5

BCF STATUS,RP0

REP

BTFSC SDA; judge whether the response has arrived, if not, wait

GOTO REP

BCF SCLK

BSF STATUS,RP0

BCF TRISB ,5

BCF STATUS,RP0

RETURN

DELAY2

NOP

NOP

NOP

NOP

RETURN

;********************************************

end ; source program ends

;*****************************************************

Reference address:Design of reading data from 24C02 to digital tube display based on PIC microcontroller

Previous article:The role of the prescaler in the PIC microcontroller
Next article:Application of Timer/Counter of PIC16F87X MCU

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号