Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

8051 vs PIC

Status
Not open for further replies.

fazt

New Member
i am doing my final year project based on the 80c51 processor
I am forced to convert a code written for a pic16f87x to a p89c51rd2.
1.i am having a hard time converting the paging in the pic and
understanding registers related to paging like Pclath and PCL and PCH
2. what does HIGH(label1) do in the following code and what can i do in 8051
label1
movlw HIGH(label1) ;***pre-load PCLATH***
movwf PCLATH
movf Index2, W; index2 is a byte
addwf PCL, F
dt "Set System Time %" ;% indicates end of table
3.what can i do with these kind of instruction
BTFSS status,z
bcf bit1; bit1 is a bit definition
 
It's probably no use trying to convert the actual code, it's FAR too different - you need to convert the 'operation' of the PIC, to duplicate it in 8051.
 
fazt said:
can any one tell me how to build took up tables in 8051s?

Assuming it's conventional Von Neuman architecture?, you simply store the data in memory, and use indexed addressing to access it - it's the Harvard architecture of the PIC which makes this impossible, which means you have to use RETLW.
 
fazt said:
can any one tell me how to build took up tables in 8051s?
What is located in the table; bytes, words, strings of fixed or variable length?
How long is the table?
Is the data in the table constant or does it change over time? First case store data in code memory, second case use external or internal RAM.

Like Nigel already said, translate what the PIC is doing into 8051 code not the code itself.
Do you have a flow chart of what the PIC is doing?
 
Table in CODE memory use
Code:
    MOVC  A,@A+DPTR
with the base address in the Data Pointer(DPTR) and the index in the accumulator.

Table in external DATA memory use
Code:
    MOVX  A,@DPTR
with the address of the table entry in the Data Pointer(DPTR)

Table in internal DATA memory use
Code:
    MOVX  A,@R0
with the address in R0 of the current register bank
 
mcs51mc said:
What is located in the table; bytes, words, strings of fixed or variable length?
How long is the table?
Is the data in the table constant or does it change over time? First case store data in code memory, second case use external or internal RAM.

Like Nigel already said, translate what the PIC is doing into 8051 code not the code itself.
Do you have a flow chart of what the PIC is doing?


The table is composed of strings with variable length. The table is 20-30 lines long. And i have flow chart of what the pic is doing. I am not directly converting the code. But i am using the same subroutines and variable naming and sometimes there is no problem directlyreplacing the equivalent instruction.
 
And you could probably write a PIC interpreter while you were at it, which would probably work at some level, but be disappointingly slow like most all interpreters.
 
1) Declare a segment in code memory to store your strings
2) Add one byte before the string with the string length
3) Add one byte at the end of each string with data 0

Code:
MyStrings	Segment CODE	SEGMENT   CODE

			RSEG MyStrings

Strings: 	DB 12,'First string',0		;Str 00
		DB  6,'Second',0		;Str 01
		DB 11,'Donald Duck',0	;Str 02
		DB  3,'Yes',0			;Str 03

4) Now write a routine to select a string and do what you want to do with it, the string you need is located in variable StringNumber

Code:
GetString:		mov  R1,StringNumber	;StringNumber + 1
			inc  R1
			mov  dptr,#Strings		;Initialize dptr with base address of strings
			djnz R1,LBL0070
			jmp  LBL0071
LBL0070:		clr  a
			movc a,@a+dptr		;Read length actual string
			add  a,dpl			;add  it to dptr 
			mov  dpl,a
			jnc  LBL0072			;check overflow
			inc  dph			;increment dph when overflow
LBL0072:		inc  dptr			;+1 byte due to string length
			inc  dptr			;+1 byte due to trailing 0
			djnz R1,LBL0070		;Reached wanted string? No: again
			
LBL0071:		inc  dptr			;Yes: inc dptr duet o string length
			mov  R7,dph			;store dptr in R7 en R6
			mov  R6,dpl
			mov  R5,#0			;Initialize character counter at 0

LBL0073:		mov  dph,R7			;Reload dptr from R6 & R7
			mov  dpl,R6
			mov  a,R5			;Character counter
			movc a,@a+dptr		;Get character into accumulator
			jz  LBL0074			;Character = 0? Yes: job done
							
			;Do what you need to do with the character here
			;In this example send it to LCD using some subs
			;Since these subs use the dptr I need to store it in R6 & R7
			;You could also push it on the stack 
			;
			mov  dptr,#LCD_DataRegister
			call LCD_Ready		;LCD Busy ??
			movx @dptr,A		;Send character to LCD
			inc  R5				;Increment character pointer
			jmp  LBL0073		;Next character

LBL0074:						;END GetString:

That’s one way, I’m sure you can come up with others.
Only one thing counts: It has to work :)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top