Файл: Microcontroller Programming. Thi Micro Chip PIC (Julio Sanchez, 2007).pdf
ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 14.06.2025
Просмотров: 8619
Скачиваний: 0
Data EEPROM Programming |
503 |
||
btfsc |
STATUS,C |
; Did subtract overflow? |
|
goto |
bump10 |
; No. Count subtraction |
|
goto |
end10 |
||
bump10: |
|||
incf |
thisDig,f |
;increment digit counter |
|
goto |
sub10 |
||
; Store 10th digit |
|||
end10: |
|||
movlw |
.10 |
||
addwf |
inNum,f |
; Adjust for last subtract |
|
movf |
thisDig,w |
; get digit counter contents |
|
addlw |
0x30 |
; Conver to ASCII |
|
movwf |
asc10 |
; Store it |
|
; Calculate and store units digit |
|||
movf |
inNum,w |
; |
Store units value |
addlw |
0x30 |
; Convert to ASCII |
|
movwf |
asc1 |
; Store digit |
|
return |
|||
;============================================================ ; EEPROM procedures ;============================================================ ;==============================
;read EEPROM ;==============================
;Procedure to read EEPROM memory. Address of memory
;location to read is stored in local register EEMemAdd
;On exit: read data in w
EERead:
bcf |
STATUS,RP0 |
; Bank |
0 |
movf |
EEMemAdd,w |
; Address to w |
|
movwf |
EEADR |
; w to |
address register |
bsf |
STATUS,RP0 |
; Bank |
1 |
bsf |
EECON1,RD |
; EE Read |
|
bcf |
STATUS,RP0 |
; Bank |
0 |
movf |
EEDATA,w |
; W = EEDATA |
|
return |
|||
;==============================
;write EEPROM ;==============================
;Procedure to write asc1 byte to EEPROM memory
;Address to write stored in local register EEMemAdd
;Data byte to write is in local register EEByte EEWrite:
;Load byte to write into EE data register
movf |
EEByte,w ; Data to w |
|
movwf |
EEDATA |
; Write |
504 |
Chapter 15 |
||
; Set write address in EE address register |
|||
movf |
EEMemAdd,w |
; Address to w |
|
movwf |
EEADR |
; w to address register |
|
; Write data to EEPROM memory |
|||
bsf |
STATUS,RP0 |
; Bank 1 |
|
bcf |
INTCON,GIE |
; Disable INTs. |
|
bsf |
EECON1,WREN ; Enable Write |
||
movlw |
0x55 |
; Code # 1 |
|
movwf |
EECON2 |
; Write 0x55 |
|
movlw |
0xaa |
; Code # 2 |
|
movwf |
EECON2 |
; Write 0xaa |
|
bsf |
EECON1,WR |
; Set WR bit |
|
; Write operation now takes place automatically |
|||
bsf |
INTCON,GIE |
; Re-enable interrupts |
|
bcf |
STATUS,RP0 |
; Bank 0 |
|
return |
|||
End
15.2.2 Ser2EEP Program
;File name: Ser2EEP.asm
;Last revision: May 26, 2006
;Author: Julio Sanchez
;PIC: 16F877
;Description:
;Receive character data through RS-232 line and store in
;EEPROM data memory. Received characters are echoed on
;the second LCD line. When <Enter> key is detected (code
;0x0d) the text stored in EEPROM memory is retrieved and
;displayed on the LCD. On startup the top LCD line displays
;the prompt: “Receiving:”. At that time a message “Rdy- ” is
;sent through the serial line so as to test the connection.
;Default serial line setting:
; |
2400 baud |
|
; |
no parity |
|
; |
1 |
stop bit |
; |
8 |
character bits |
; |
||
;Program to use 4-bit PIC-to-LCD interface.
;Code assumes that LCD is driven by Hitachi HD44780
;controller and PIC 16F977. Display supports two lines
;each one with 20 characters. The length, wiring and base
;address of each display line is stored in #define
;statements. These statements can be edited to accommodate
;a different set-up.
506 |
Chapter 15 |
|
Bank0 |
MACRO |
; Select RAM bank 0 |
bcf |
STATUS,RP0 |
|
bcf |
STATUS,RP1 |
|
ENDM |
||
Bank1 |
MACRO |
; Select RAM bank 1 |
bsf |
STATUS,RP0 |
|
bcf |
STATUS,RP1 |
|
ENDM |
||
Bank2 |
MACRO |
; Select RAM bank 2 |
bcf |
STATUS,RP0 |
|
bsf |
STATUS,RP1 |
|
ENDM |
||
Bank3 |
MACRO |
; Select RAM bank 3 |
bsf |
STATUS,RP0 |
|
bsf |
STATUS,RP1 |
|
ENDM |
||
;===================================================== |
||
; |
constant definitions |
|
; for PIC-to-LCD pin wiring and LCD line addresses ;=====================================================
#define E_line 1 |
;| |
|
#define RS_line 0 |
;| — from wiring diagram |
|
#define RW_line 2 |
;| |
|
; LCD line addresses (from LCD data sheet) |
||
#define LCD_1 |
0x80 |
; First LCD line constant |
#define LCD_2 |
0xc0 |
; Second LCD line constant |
#define LCDlimit .20; Number of characters per line #define spbrgVal .64; For 2400 baud on 10Mhz clock
;Note: The constants that define the LCD display
;line addresses have the high-order bit set
;so as to meet the requirements of controller
;commands.
;
;========================================================== ; General Purpose Variables ;==========================================================
;Local variables
;Reserve 20 bytes for string buffer cblock 0x20
strData endc
;Other data
cblock 0x34 |
; Start of block |
|||
count1 |
; |
Counter |
# |
1 |
count2 |
; |
Counter |
# |
2 |
Data EEPROM Programming |
507 |
count3 |
; Counter # 3 |
J |
; counter J |
K |
; counter K |
bufAdd |
|
index |
|
store1 |
; Local storage |
store2 |
|
endc |
;==============================
;Common RAM area ;==============================
;These GPRs can be accessed from any bank.
;15 bytes are available, from 0x70 to 0x7f
cblock 0x70
; For LCDscroll procedure
LCDcount ; Counter for characters per line
LCDline |
; Current display line (0 or 1) |
; Communications variables |
|
newData |
; not 0 if new data received |
ascVal |
|
errorFlags |
|
; EEPROM-related variables
EEMemAdd ; EEPROM address to access
EEByte |
; Data byte to write |
endc |
;============================================================
; P R O G R A M
;============================================================
org |
0 |
; start at address |
goto |
main |
|
; Space for interrupt handlers |
||
org |
0x08 |
|
main: |
||
;Wiring:
;LCD data to Port-D, lines 0 to 7
;E line -> Port-E, 1
;RW line -> Port-E, 2
;RS line -> Port-E, 0
;Set PORTE D and E for output
;First, initialize Port-B by clearing latches clrf STATUS
clrf PORTB
;Select bank 1 to TRIS Port-D for output Bank1
;TRIS Port-D for output. Port-D lines 4 to 7 are wired
;to LCD data lines. Port-D lines 0 to 4 are wired to LEDs. movlw B’00000000’