Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Proteus PIC internaal EEPROM Simulation

Status
Not open for further replies.

duryan

Newbie level 4
Joined
Dec 1, 2011
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,342
hi guys! im new in this forum. i would like to ask help from you. currently im working on PIC18F4550's internal EEPROM. im planning to write data to location 0 and output it to portb just to verify if it is working. hoping for your reply and have a nice day.
 

Hi and Welcome,

So what do you need help with ?

You can do that either in Mplabs Sim by viewing the File Registers and Watch Windows or with Proteus Isis.

If you hare having problems then post you code and .dsn so we can see what is going wrong.
 

here's my code and so far its working

include <p18f4550.inc>

org 0x00

; configure data port direction
clrf TRISD

checkWR:
btfsc EECON1, WR
goto checkWR

movlw 0x00 ; address in EEPROM
movwf EEADR
movlw 0xF1 ; data to write 0x77 = 1111 0001
movwf EEDATA

bcf EECON1, EEPGD
bcf EECON1, CFGS
bsf EECON1, WREN
bcf INTCON, GIE ; disable interrupt

movlw 0x55
movwf EECON2
movlw 0xAA
movwf EECON2
bsf EECON1, WR

nop
nop

checkWRDone:
btfsc EECON1, WR
goto checkWRDone

bsf INTCON, GIE
bcf EECON1, WREN

; reading the data for verification
movlw 0x00
movwf EEADR

bcf EECON1, EEPGD
bcf EECON1, CFGS
bsf EECON1, RD
movf EEDATA, w

movwf PORTD
wait:
goto wait
end

I really appreciate it if you make some comments or recommendations. thank you!
 

Hi,

Have Simulated your code and yes it runs ok.

However you will not get very far with any more code as you are missing some important code.

It may seem like a lot of unnecessary stuff but most is essential.

For most pic10 to 18F chips there are the TEMPLATES files found in MPASM.

I have merged your code with the 4550 template files .

I have also added a basic but very important CONFIG line.
Key point, it selects the chips Internal Oscillator so no need to use a crystal.
Also at the beginning of the Main code is the OSCCON instruction which selects the speed the internal oscillator will run at.

hth

Code:
;******************************************************************************
;   This file is a basic template for assembly code for a PIC18F4550. Copy    *
;   this file into your project directory and modify or add to it as needed.  *
;                                                                             *
;   Refer to the MPASM User's Guide for additional information on the         *
;   features of the assembler.                                                *
;                                                                             *
;   Refer to the PIC18Fx455/x550 Data Sheet for additional                    *
;   information on the architecture and instruction set.                      *
;                                                                             *
;******************************************************************************
;                                                                             *
;    Filename:                                                                *
;    Date:                                                                    *
;    File Version:                                                            *
;                                                                             *
;    Author:                                                                  *
;    Company:                                                                 *
;                                                                             * 
;******************************************************************************
;                                                                             *
;    Files Required: P18F4550.INC                                             *
;                                                                             *
;******************************************************************************

	LIST P=18F4550		;directive to define processor
	#include <P18F4550.INC>	;processor specific variable definitions

;******************************************************************************
;Configuration bits
;Microchip has changed the format for defining the configuration bits, please 
;see the .inc file for futher details on notation.  Below are a few examples.



;   Oscillator Selection:
    
 CONFIG FOSC=INTOSCIO_EC,  WDT=OFF, PWRT=ON, BOR=OFF, MCLRE=OFF, LPT1OSC=OFF, XINST=OFF
 CONFIG LVP=OFF, VREGEN=OFF, PBADEN=OFF, DEBUG=OFF

;******************************************************************************
;Variable definitions
; These variables are only needed if low priority interrupts are used. 
; More variables may be needed to store other special function registers used
; in the interrupt routines.

		CBLOCK	0x080
		WREG_TEMP	;variable used for context saving 
		STATUS_TEMP	;variable used for context saving
		BSR_TEMP	;variable used for context saving
		ENDC

		CBLOCK	0x000
		EXAMPLE		;example of a variable in access RAM
		ENDC

;******************************************************************************
;EEPROM data
; Data to be programmed into the Data EEPROM is defined here

		ORG	0xf00000

		DE	"Test Data",0,1,2,3,4,5

;******************************************************************************
;Reset vector
; This code will start executing when a reset occurs.

		ORG	0x0000

		goto	Main		;go to start of main code

;******************************************************************************
;High priority interrupt vector
; This code will start executing when a high priority interrupt occurs or
; when any interrupt occurs if interrupt priorities are not enabled.

		ORG	0x0008

		bra	HighInt		;go to high priority interrupt routine

;******************************************************************************
;Low priority interrupt vector and routine
; This code will start executing when a low priority interrupt occurs.
; This code can be removed if low priority interrupts are not used.

		ORG	0x0018

		movff	STATUS,STATUS_TEMP	;save STATUS register
		movff	WREG,WREG_TEMP		;save working register
		movff	BSR,BSR_TEMP		;save BSR register

;	*** low priority interrupt code goes here ***


		movff	BSR_TEMP,BSR		;restore BSR register
		movff	WREG_TEMP,WREG		;restore working register
		movff	STATUS_TEMP,STATUS	;restore STATUS register
		retfie

;******************************************************************************
;High priority interrupt routine
; The high priority interrupt code is placed here to avoid conflicting with
; the low priority interrupt vector.

HighInt:

;	*** high priority interrupt code goes here ***


		retfie	FAST

;******************************************************************************
;Start of main program
; The main program code is placed here.

Main:

;	*** main code goes here ***


		movlw	b'01100010'		; set internal osc to 4 mhz
		movwf	OSCCON



	; configure data port direction
	clrf TRISD
	
checkWR:
	btfsc EECON1, WR
	goto checkWR
	
	movlw 0x00 ; address in EEPROM
	movwf EEADR
	movlw 0x22 ; data to write 0x77 = 1111 0001
	movwf EEDATA
	
	bcf EECON1, EEPGD
	bcf EECON1, CFGS
	bsf EECON1, WREN
	bcf INTCON, GIE ; disable interrupt
	
	movlw 0x55
	movwf EECON2
	movlw 0xAA
	movwf EECON2
	bsf EECON1, WR
	
	nop
	nop
	
checkWRDone:
	btfsc EECON1, WR
	goto checkWRDone
	
	bsf INTCON, GIE
	bcf EECON1, WREN




	; reading the data for verification
	movlw 0x00
	movwf EEADR
	
	bcf EECON1, EEPGD
	bcf EECON1, CFGS
	bsf EECON1, RD
	movf EEDATA, w
	
	movwf PORTD
wait:
	goto wait


	end 





;******************************************************************************
;End of program
 

Thank you for the reply. I would like to ask the following.

; Oscillator Selection:

CONFIG FOSC=INTOSCIO_EC, WDT=OFF, PWRT=ON, BOR=OFF, MCLRE=OFF, LPT1OSC=OFF, XINST=OFF
CONFIG LVP=OFF, VREGEN=OFF, PBADEN=OFF, DEBUG=OFF

This code is needed during compilation in MPLAB and for actually execution of the code in PIC MCU?

;EEPROM data
; Data to be programmed into the Data EEPROM is defined here

ORG 0xf00000

DE "Test Data",0,1,2,3,4,5

The address of Data EEPROM is 0xF00000? Is there another way to access it directly without using EEADR and EEDATA?

movlw b'01100010' ; set internal osc to 4 mhz
movwf OSCCON

really? PIC184550 can use internal oscillator and does not need an external crystal oscillator? If its true then its a good news for me :-D

I really appreciate this forum and I believe that learning never ends. I hope that I can learn more things from you guys. Have a nice day!

---------- Post added at 11:06 ---------- Previous post was at 10:43 ----------

I've checked the template of 4550 in MPLAB and it has this line

; Oscillator Selection:
CONFIG FOSC = XT_XT ;XT oscillator, XT used by USB

Can you please explain the meaning of each config?

; Oscillator Selection:

CONFIG FOSC=INTOSCIO_EC, WDT=OFF, PWRT=ON, BOR=OFF, MCLRE=OFF, LPT1OSC=OFF, XINST=OFF
CONFIG LVP=OFF, VREGEN=OFF, PBADEN=OFF, DEBUG=OFF

This config is also applicable in MikroC?

---------- Post added at 11:30 ---------- Previous post was at 11:06 ----------

can you convert the asm code in MikroC? please...
 

CONFIG FOSC=INTOSCIO_EC, WDT=OFF, PWRT=ON, BOR=OFF, MCLRE=OFF, LPT1OSC=OFF, XINST=OFF
CONFIG LVP=OFF, VREGEN=OFF, PBADEN=OFF, DEBUG=OFF

The Config is used when programming the chip - it tells the Pic how to set things up to be used with your code being programmed.
If you leave it out Defaults will be applied, do you know what they are.
If you post any code to a forum its important to show the Config lines so we can see how you have set things up.


The address of Data EEPROM is 0xF00000? Is there another way to access it directly without using EEADR and EEDATA?

Not that I know of, but you make it easier to read and write eeprom code by creating auto address incrementing subroutines for large amounts of data.

really? PIC184550 can use internal oscillator and does not need an external crystal oscillator? If its true then its a good news for me

Many Pic chips have onboard oscillators some even have RTCs.

; Oscillator Selection:
CONFIG FOSC = XT_XT ;XT oscillator, XT used by USB

That line tells the Pic to use an External oscillator up to 4Mhz
See the Oscillator Section of the Datasheet for full details.

Also look at the 18F4550.inc file - this contains all the options for the Config codes and system details - in the MPASM directory.


This config is also applicable in MikroC?

Yes, its independant of any compiler

can you convert the asm code in MikroC? please..

No, don't do C
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top