PDA

View Full Version : problem with input and output (18F452)



turkuaz
- 17th March 2008, 16:05
I use 18F452 4MGz xt.some of the codes are below.
I use PORTA ,PORTC and PORTE output.INPUT PORTD.3 INPUT PORTC.6 INPUT PORTC.4
LCD and keypad working nice but INPUT and OUTPUT ports not working.
Is there anybody to help me .
Thanks.

INCLUDE "KeyPad.bas"

---------------------------------
---------------------------------

'Define LCD connections
Define LCD_DREG PORTD
Define LCD_DBIT 4
Define LCD_RSREG PORTD
Define LCD_RSBIT 0
Define LCD_EREG PORTD
Define LCD_EBIT 1
DEFINE LCD_BITS 4
DEFINE LCD_LINES 4
DEFINE LCD_RWREG PORTE
DEFINE LCD_RWBIT 2
'Define keypad connections
DEFINE KEYPAD_ROW 4 ' 4 ROW keypad Tuştakımı yatay
DEFINE KEYPAD_ROW_PORT PORTB ' ROW port = PORTB
DEFINE KEYPAD_ROW_BIT 4 ' ROW0 = PORTB.4
DEFINE KEYPAD_COL 4 ' 4 COL keypad Tuştakımı kolon
DEFINE KEYPAD_COL_PORT PORTB ' COL port = PORTB
DEFINE KEYPAD_COL_BIT 0 ' COL0 = PORTB.0
DEFINE KEYPAD_DEBOUNCEMS 100 ' debounce delay = 20 mSec
DEFINE KEYPAD_AUTOREPEAT 1 ' use auto-repeat feature
' Define program variables
tus var byte ' tus değeri
sayim VAR word
ma VAR word
nm VAR word
hy VAR word
sy150 VAR word
sy40 VAR word
tyag VAR word
thacim VAR word

INTCON2.7 = 0 ' Enable PORTB pullups (18F452)
ADCON1 = 7 ' PORTA PORTE digital
TRISC = %00000000
TRISE.0 = 0
TRISE.1 = 0
TRISE.2 = 0
LOW PORTE.0
LOW PORTE.1
LOW PORTE.2' LCD R/W low (write)
LOW PORTC.0
LOW PORTC.1
LOW PORTC.2
LOW PORTC.3
LOW PORTC.5
LOW PORTC.7
LOW PORTA.0
LOW PORTA.1
LOW PORTA.2
LOW PORTA.3
LOW PORTA.4
LOW PORTA.5
INPUT PORTD.3 'TEMAS TUŞU
INPUT PORTC.6
INPUT PORTC.4 ' SİNYAL GİRİŞİ
Pause 200 ' LCD açılması için bekle

---------------
--------------
........
Thanks

sougata
- 17th March 2008, 16:12
TRISE.0 = 0
TRISE.1 = 0
TRISE.2 = 0



Use instead


TRSIE = 0


PIC18F452 has a parallel port (PMP) similar to a microprocessor bus which uses the TRISE register for the configuration and the PORTE as the control line for the PORTD (PMP) read write. Other bits (7 to 4) are used to configure this.

Hope this helps

Archangel
- 17th March 2008, 16:24
TrisD = %00001000 ' all port d as outputs except bit 3 input
TrisC = %01010000 ' all port c outputs except bits 6 and 4 inputs
TrisA = %00000000 ' all port a as outputs
TrisB = %11110000 ' lower 4 bits outputs upper inputs
TrisE = %00000000 ' all 8 bits as outputs
edit: Sougata undoubtly knows what he is talking about and posted while I was writing.

Phil Moore
- 17th March 2008, 23:21
And make sure that all your DEFINE statements are in upper case, ie:

Define LCD_DREG PORTD

should be

DEFINE LCD_DREG PORTD

(Skimask & Bruce pointed this out to me last week!)

Phil.