CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PIC16F876 problem : Possible bug

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guard



Joined: 20 Jan 2005
Posts: 43

View user's profile Send private message

PIC16F876 problem : Possible bug
PostPosted: Fri Jan 21, 2005 5:18 am     Reply with quote

Hi,
PCW 3.216
may be SET_tris_c not function..
This is my simple code for test:
#include "C:firmware\Test.h"

void main()
{


setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);


Set_tris_C(0);


a:

output_high(PIN_C4);


goto a;

this is asm code :
1: #include "C:\firmware\Test.h"
000000 3000 MOVLW 0
000001 08A MOVWF PCLATH
000002 2804 GOTO 0x4
000003 000 NOP
000004 23FF CALL 0x3ff
000005 1683 BSF STATUS, 0x5
000006 090 MOVWF T1CON
000007 3000 MOVLW 0
000008 08A MOVWF PCLATH
000009 280A GOTO @cinit

11: void main()
12: {
00000A 184 CLRF FSR
00000B 301F MOVLW 0x1f
00000C 583 ANDWF STATUS, 0x1
00000D 131F BCF ADCON0, 0x6
00000E 3000 MOVLW 0
00000F 3807 IORLW 0x7
000010 1683 BSF STATUS, 0x5
000011 091 MOVWF 0x11
000012 3007 MOVLW 0x7
000013 1283 BCF STATUS, 0x5
000014 099 MOVWF CMCON
000015 1683 BSF STATUS, 0x5
000016 805 MOVF PORTA, 0
000017 1283 BCF STATUS, 0x5
000018 819 MOVF CMCON, 0
000019 118C BCF PIR1, 0x3

14:
15: setup_adc_ports(NO_ANALOGS|VSS_VDD);
00001A 131F BCF ADCON0, 0x6
00001B 3000 MOVLW 0
00001C 1683 BSF STATUS, 0x5
00001D 091 MOVWF 0x11
16: setup_adc(ADC_OFF);
00001E 1283 BCF STATUS, 0x5
00001F 101F BCF ADCON0, 0
17: setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
000020 1683 BSF STATUS, 0x5
000021 801 MOVF TMR0, 0
000022 39C0 ANDLW 0xc0
000023 3808 IORLW 0x8
000024 081 MOVWF TMR0
18: setup_timer_1(T1_DISABLED);
000025 1283 BCF STATUS, 0x5
000026 190 CLRF T1CON
19: setup_comparator(NC_NC_NC_NC);
000027 3007 MOVLW 0x7
000028 099 MOVWF CMCON
000029 1683 BSF STATUS, 0x5
00002A 805 MOVF PORTA, 0
00002B 3003 MOVLW 0x3
00002C 1283 BCF STATUS, 0x5
00002D 0A0 MOVWF 0x20
00002E BA0 DECFSZ 0x20, 0x1
00002F 282E GOTO 0x2e
000030 819 MOVF CMCON, 0
000031 118C BCF PIR1, 0x3
20: setup_vref(FALSE);
000032 1683 BSF STATUS, 0x5
000033 199 CLRF CMCON
21:
22:
23: set_tris_C(0);
000034 3000 MOVLW 0
000035 087 MOVWF PORTC <<<----------------------------WHY PORTC?? and not tris?


24:
25:
26:
27: a:
28:
29: output_high(PIN_c4);
000036 1207 BCF PORTC, 0x4
000037 1283 BCF STATUS, 0x5
000038 1607 BSF PORTC, 0x4
30:
31:
32: goto a;
000039 1683 BSF STATUS, 0x5
00003A 2836 GOTO 0x36
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Fri Jan 21, 2005 5:38 am     Reply with quote

It seems the compiler is naming the registers wrong, but the code should work properly.
You see, the opcode for MOVWF is 00 0000 1fff ffff (fff ffff represents the memory address). This means it can write into addresses as high as 0x7F.
PORTC is located at 0x07, and TRISC is at 0x87. To write to 0x87, compiler has to choose bank 1 and write to 0x07. If you look at the generated code, you'll see 000032 1683 BSF STATUS, 0x5 which means the compiler is selecting bank 1, and at 000035 087 MOVWF PORTC it is writing to 0x07. This is correct code, but the ASM description of it is a bit confusing.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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