cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1 MCU

New Contributor II

 Is there any way to read the Program Counter value of a particular point in my code? I want to store this value in a varaiable and process it. (specifically for PSoC3).

0 Likes
Reply
1 Solution
Employee

 Program Counter register addresses can be found from PSoC3 Registers TRM.(Link:http://www.cypress.com/?rID=37833). But this register cannot be accessed using CY_GET_REG API's. It can be accessed only when CPU is in halt state.

View solution in original post

0 Likes
Reply
6 Replies
Employee

 Program Counter register addresses can be found from PSoC3 Registers TRM.(Link:http://www.cypress.com/?rID=37833). But this register cannot be accessed using CY_GET_REG API's. It can be accessed only when CPU is in halt state.

View solution in original post

0 Likes
Reply
Employee

 Another method for reading the value will be using assembly instructions. These steps can be used to read the Program Coounter Value.

   

1)Use LCALL. When LCALL is used the Program counter value will be pushed on to stack.
2)Use POP instruction to read 
stack register value to DPL and DPH register.
3)Store the DPH DPL values to 
the variable.

Employee

While adding assebly instructions,please refer the knowledge base article available in the link : http://www.cypress.com/?rID=43621 

Employee

 Please check the code snippet given below. Please add the same in your project. The Program Counter Value corresponding to the label here: will be stored in the variable ProgramCounterValue.

   

 

   

uint16 ProgramCounterValue;

   

/*---- This assembly code will store the Program Counter value to the variable ProgramCounter----- */

   

   

#pragma asm   

   

LCALL here

   

    here:

   

       POP DPH1

   

       POP DPL1

   

  

   

MOV DPTR, #ProgramCounterValue?040

   

MOV A, DPH1

   

MOVX @DPTR, A

   

INC DPTR

   

MOV A, DPL1

   

MOVX @DPTR, A

   

#pragma endasm 

   

   

/*----End of the assembly block ------ */

Employee
Employee

The above attached project will print the Program Counter value on the LCD Screen.

0 Likes
Reply