golson
Joined: 24 Apr 2006 Posts: 5
|
Why can't I write to Port B with this inline code? |
Posted: Mon Apr 24, 2006 1:15 pm |
|
|
/////////////////////////////////////////////////////////////////////////
//// TEST_APR24.C ////
//// ////
//// This program will output multiple words out of port b in a ////
//// infinite loop to test the speed the PIC will run at. ////
//// ////
/////////////////////////////////////////////////////////////////////////
#if defined(__PCM__)
#include <16F874.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#endif
inline void write_port(int8 address, int8 data);
inline void set_tris_output(int8 address);
void main()
{
set_tris_output(0x6);
write_port(0x6, 1);
while(TRUE) { }; // loop forever
}
/////////////////////////////////////////////////////////////////////
// Purpose: write to a port or register assume port is set up already as output
// args:
//
// return: none
/////////////////////////////////////////////////////////////////////
inline void write_port(int8 address, int8 data)
{
#asm
MOVLW data
MOVWF address
#endasm
return;
}
/////////////////////////////////////////////////////////////////////
// Purpose: set_tris_input(int8 address) // place bidirectional port as output
//
// args:
//
// return: none
/////////////////////////////////////////////////////////////////////
inline void set_tris_output(int8 address) // place bidirectional port as input
{
#asm
MOVLW 0x00 // set tris register as input
BSF 03.5 // raise hi addr bit to select tris
MOVWF address // write to tris register all 00s
#endasm
return;
}
Below is the listing:
--- C:\PICGARY\TEST_APR24\TEST_APR24.c ---------------------------------------------------------
1: /////////////////////////////////////////////////////////////////////////
000 3000 MOVLW 0
001 008A MOVWF 0xa
002 2804 GOTO 0x4
003 0000 NOP
2: //// TEST_APR24.C ////
3: //// ////
4: //// This program will output multiple words out of port b in a ////
5: //// infinite loop to test the speed the PIC will run at. ////
6: //// ////
7: /////////////////////////////////////////////////////////////////////////
8: #if defined(__PCM__)
9: #include <16F874.h>
10: #fuses HS,NOWDT,NOPROTECT,NOLVP
11: #use delay(clock=20000000)
12: #endif
13:
14: inline void write_port(int8 address, int8 data);
15: inline void set_tris_output(int8 address);
16:
17:
18: void main()
19: {
004 0184 CLRF 0x4
005 301F MOVLW 0x1f
006 0583 ANDWF 0x3, F
007 1683 BSF 0x3, 0x5
008 141F BSF 0x1f, 0
009 149F BSF 0x1f, 0x1
00A 151F BSF 0x1f, 0x2
00B 119F BCF 0x1f, 0x3
20:
21: set_tris_output(0x6);
00C 3006 MOVLW 0x6
00D 1283 BCF 0x3, 0x5
00E 00A6 MOVWF 0x26
22: write_port(0x6, 1);
012 3006 MOVLW 0x6
013 00A6 MOVWF 0x26
014 3001 MOVLW 0x1
015 00A7 MOVWF 0x27
23:
24: while(TRUE) { }; // loop forever
018 2818 GOTO 0x18
25:
26: }
27:
28: /////////////////////////////////////////////////////////////////////
29: // Purpose: write to a port or register assume port is set up already as output
30: // args:
31: //
32: // return: none
33: /////////////////////////////////////////////////////////////////////
34: inline void write_port(int8 address, int8 data)
35: {
019 0063 SLEEP
36: #asm
37: MOVLW data
016 3027 MOVLW 0x27
38: MOVWF address
017 00A6 MOVWF 0x26
39: #endasm
40: return;
41:
42: }
43:
44: /////////////////////////////////////////////////////////////////////
45: // Purpose: set_tris_input(int8 address) // place bidirectional port as output
46: //
47: // args:
48: //
49: // return: none
50: /////////////////////////////////////////////////////////////////////
51: inline void set_tris_output(int8 address) // place bidirectional port as input
52: {
53: #asm
54: MOVLW 0x00 // set tris register as input
00F 3000 MOVLW 0
55: BSF 03.5 // raise hi addr bit to select tris
010 1683 BSF 0x3, 0x5
56: MOVWF address // write to tris register all 00s
011 00A6 MOVWF 0x26
OK. Above I tried to write to address 0x6 which is portb. The Assembly output forced the address somewhere else. in this case the address is
0x26 which would be in the ram. I intended to move the data into portb.
I do not want to use the output_b at this time. I am trying to control port
writes with a minimal number of instructions. This also is supposed to be inline commands. I do not want to cause extra jumps in the code or Stack
operations that slow down the code with extra instructions.
Thank You for your time,
Gary Olson |
|