|
|
View previous topic :: View next topic |
Author |
Message |
slekhakul Guest
|
What did I do wrong with this C code? |
Posted: Sun Feb 02, 2003 4:47 pm |
|
|
I am trying to write a C code for simple I/O by making port b as input and port d as output using set_tris_x function.
#include <16f877.h>
#fuses xt, nowdt
#byte b_port = 6
#byte d_port = 8
void main (void)
{
int i;
set_tris_b(0xff); // port b is input
set_tris_d(0x00); // port d is output
do {
i = b_port; // read port b
d_port = i; // write to port d
}while(true);
}
It did not work. I looked at the list file and found out that the C statement set_tris_d(0x00) instead to write 00 to trisd (SFR 8), it write 00 to trisc (SFR 7). What did I do wrong?
The list file is at follows:
CCS PCW C Compiler, Version 3.050, 12819
Filename: c:\documents and settings\slekhakul\my documents\ee 422\pic lab\lab1a.LST
ROM used: 26 (0\%)
Largest free fragment is 2048
RAM used: 7 (4\%) at main() level
7 (4\%) worst case
Stack: 0 locations
*
0000: MOVLW 00
0001: MOVWF 0A
0002: GOTO 004
0003: NOP
.................... #include <16f877.h>
.................... //////// Standard Header file for the PIC16F877 device ////////////////
.................... #device PIC16F877
.................... #list
....................
.................... #fuses xt, nowdt
.................... #byte b_port = 6
.................... #byte d_port = 8
....................
.................... void main (void)
.................... {
.................... int i;
0004: CLRF 04
0005: MOVLW 1F
0006: ANDWF 03,F
0007: MOVLW 9F
0008: MOVWF 04
0009: MOVLW 07
000A: MOVWF 00
000B: MOVLW FF
000C: MOVWF 20
.................... set_tris_b(0xff); // port b is input
000D: MOVLW FF
000E: BSF 03.5
000F: MOVWF 06
.................... set_tris_d(0x00); // port d is output
0010: MOVLW 00 <===============
0011: MOVWF 07 <=============== 07 is TRISC!
0012: BCF 03.5
0013: MOVWF 20
.................... do {
.................... i = b_port; // read port b
0014: MOVF 06,W
0015: MOVWF 21
.................... d_port = i; // write to port d
0016: MOVF 21,W
0017: MOVWF 08
.................... }while(true);
0018: GOTO 014
.................... }
....................
0019: SLEEP
___________________________
This message was ported from CCS's old forum
Original Post ID: 11213 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: What did I do wrong with this C code? |
Posted: Sun Feb 02, 2003 7:10 pm |
|
|
:=I am trying to write a C code for simple I/O by making port b as input and port d as output using set_tris_x function.
:=
:=It did not work. I looked at the list file and found out that the C statement set_tris_d(0x00) instead to write 00 to trisd (SFR 8), it write 00 to trisc (SFR 7). What did I do wrong?
:=The list file is at follows:
:=
:=CCS PCW C Compiler, Version 3.050, 12819
:=
:= Filename: c:\documents and settings\slekhakul\my documents\ee 422\pic lab\lab1a.LST
:=.................... set_tris_b(0xff); // port b is input
:=000D: MOVLW FF
:=000E: BSF 03.5
:=000F: MOVWF 06
:=.................... set_tris_d(0x00); // port d is output
:=0010: MOVLW 00 <===============
:=0011: MOVWF 07 <=============== 07 is TRISC!
:=0012: BCF 03.5
:=0013: MOVWF 20
------------------------------------------------------------
Here is a line from a previous CCS versions page:
3.052 SET_TRIS_D and E were broke in 3.050, 3.051 now restored
You can fix this by defining a macro for your
own "set_tris_d" function. See the example below:
#include "c:\progra~1\Picc\Devices\16F877.h"
#use delay(clock=8000000)
#fuses HS ,NOWDT, PUT, BROWNOUT, NOLVP
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#byte TRIS_D_REG = 0x88
#define my_set_tris_d(value) TRIS_D_REG = value
//===================================================
main ()
{
//set_tris_d(0x55);
my_set_tris_d(0x55);
while(1);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 11215 |
|
|
|
|
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
|