|
|
View previous topic :: View next topic |
Author |
Message |
INT01
Joined: 21 Feb 2011 Posts: 5
|
setup_timer_2 function |
Posted: Thu Oct 06, 2011 4:19 am |
|
|
When I use the setup_timer_2() function I get this:
Code: |
491: setup_timer_2(T2_DIV_BY_16,255,5);
10D2 0E20 MOVLW 0x20
10D4 0906 IORLW 0x6
10D6 6ECA MOVWF SSP1MSK, ACCESS
10D8 0EF9 MOVLW 0xff
10DA 6ECB MOVWF SSP1CON3, ACCESS
|
Why?
PIC18F46K22 with V4.114 |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Thu Oct 06, 2011 9:44 am |
|
|
I suggest reading the section on Special Function Registers as well as the SSP chapters for whatever PIC you're using.
Then 'play computer' and see what bits are being set/cleared on those registers.
Learn by doing....the more you read, the more you'll understand. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Oct 06, 2011 2:36 pm |
|
|
Quote: |
When I use the setup_timer_2() function I get this:
setup_timer_2(T2_DIV_BY_16,255,5);
10D2 0E20 MOVLW 0x20
10D4 0906 IORLW 0x6
10D6 6ECA MOVWF SSP1MSK, ACCESS
10D8 0EF9 MOVLW 0xff
10DA 6ECB MOVWF SSP1CON3, ACCESS
Why?
PIC18F46K22 with V4.114
|
That function writes to the wrong registers in your compiler version.
Here's a macro that will replace the defective function. Just put it
above main() as shown below. Then call setup_timer_2() and it will
put in the correct code. Example:
Code: |
#include <18F46K22.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
// This macro replaces the CCS built-in function setup_timer_2():
#byte T2CON = 0xFBA
#byte PR2 = 0xFBB
#define setup_timer_2(t2_mode, t2_period, t2_ps) \
T2CON = (t2_mode | ((t2_ps -1) << 3)); \
PR2 = (t2_period);
//======================================
void main(void)
{
setup_timer_2(T2_DIV_BY_16, 255, 5);
while(1);
}
|
This problem doesn't occur in vs. 4.124. CCS must have fixed it sometime
after vs. 4.114. (Note: This is a problem with 18F46K22 for that version,
not all PICs). |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|