Hi all
(sorry about the long post!)
Thanks to all those who have helped me and lots of late nights reading and 'PIC'-ing, I have finally reached a stage where I have and LCD connected, a keypad, capturing input from the keypad and have been playing around with SEROUT with the intention of transmitting a byte or a few bytes wirelessly.
To begin testing (after playing around with serout) I have interconnected my two pics (16f887 and 18f4520) by mean of wires.
Like this :
PIC 16f887 PIC 18F4520
PORTC.6(TX)-----PORTC.7(RX)
PORTC.7(RX)-----PORTC.6(TX)
I have setup my code to send "key pressed or received value is" as a loop text string using serout from
PIC 16f887 to the 18f4520.
The 18f4520 is set to receive using serinCode:loopy: high LED ' First LED on Pause 1000 ' Delay for .5 seconds low led Pause 1000 ' Delay for .5 seconds SerOut PORTC.6,T2400,["are you receiving this tx from 16f887 ",datatx] pause 1000 Goto loopy ' Go back to loop and blink LED forever End
I press a key on the 4x4 keypad connected to the 18f4520,Code:SerIn PORTC.7,T2400,DataRX
the keypress is stored as a variable (myvar) and myvar is made to equal datatx)
I then display datatx (the keypress) on the lcd)
Then I fetch the input (RX) from the other PIC using SERIN
The input is held in variable datarx.
I then display datarx on the LCD
Once that's done I send the same variable datarx to the PC's com port using serout.
And end off with the string "end of transmission" on LCD.
I then use the serout line
Well .... it works.
Problem is it only happens once ! yes one time and then LCD goes blank and no matter how many keystrokes I press nothing else happens :-(
So.... I think perhaps the serout/serin where my problems lie.
Maybe full RX buffers or something else.
Maybe I'm not passing the variables correctly.
I would really appreciate if somone could have a quick look at my code and possibly tell me what I am missing or doing wrong.
Kind regards
Dennis
Here is the code for each PIC
PIC16f887
PIC 18F4520Code:'************************************* 'Transmit to PIC 18f4520 serout loop '************************************* '@__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_ON & _LVP_OFF & _CP_OFF 'Ocsillator selections here 'OSCCON = %01100001 for 4mhz, or OSCCON = %01110001for 8mhz ' OSCCON = %01110001 'Int CLK 8MHz ' ANSEL= %11111111 '$0F = disable A/D converter ' option_reg = 7 'switch pull-ups ON 'END of oscillator selections 'timer/oscillator defines ' define osc 8 '8MHz 'END of timer/oscillator defines 'clear the ports OSCCON = %01110001 'Int CLK 8MHz ANSEL = %00000000 'All digital OPTION_REG.7 = 0 'Weak pull-ups enabled DEFINE OSC 8 '8MHz PORTA=0 PORTB=0 PORTC=0 PORTD=0 PORTE=0 'end of port clear 'Port IO directions and presets for port pins begin here 'TRISX = %76543210 << tris bit order numbering 'TRISA = %11111111 << 'All pins are outputs '// Define port pins as inputs and outputs ... TRISA = %00000000 'example only - TRISB = %00001111 ;Make B4-B7 outputs, B0-B3 inputs, TRISB = %11111111 'for 4x4 keypad all input TRISC = %10000000 TRISD = %00000000 TRISE.0 = 0 TRISE.1 = 0 TRISE.2 = 0 'End of Port IO directions and presets for port pins begin here 'variables begin here myvar var byte datatx var byte datarx var byte 'end of variables LED var PORTd.0 ' Alias PORTD.0 to LED loopy: high LED ' LED on Pause 1000 ' Delay for .5 seconds low led 'LED off Pause 1000 ' Delay for .5 seconds SerOut PORTC.6,T2400,["are you receiving this tx from 16f887 ",datatx] pause 1000 Goto loopy ' Go back to loop and blink LED forever End 'End of all code
Code:'************************************* 'Keypress display on LCD and TX to wherever '************************************* 'Ocsillator selections here OSCCON = $70 'Int CLK 8MHz OSCTUNE.6 = 1 'PLL 4x ADCON1= %00001111 '$0F = disable A/D converter cmcon = 7 INTCON2.7 = 0 'switch pull-ups ON 'END of oscillator selections 'timer/oscillator defines DEFINE OSC 32 '4x 8MHz 'END of timer/oscillator defines 'Port IO directions and presets for port pins begin here 'TRISX = %76543210 << tris bit order numbering 'TRISA = %11111111 'All pins are outputs '// Define port pins as inputs and outputs ... TRISA = %00000000 'example only - TRISB = %00001111 ;Make B4-B7 outputs, B0-B3 inputs, TRISB = %11111111 'for 4x4 keypad all input TRISC = %10000000 TRISD = %00000000 TRISE.0 = 0 TRISE.1 = 0 TRISE.2 = 0 'End of Port IO directions and presets for port pins begin here 'variables begin here myvar var byte datatx var byte datarx var byte 'end of variables 'LCD defines begin here DEFINE LCD_BITS 4 'defines the number of data interface lines (4 or 8) DEFINE LCD_DREG PORTD 'defines the port where data lines are connected to DEFINE LCD_DBIT 4 'defines the position of data lines for 4-bit interface (0 or 4) DEFINE LCD_RSREG PORTD 'defines the port where RS line is connected to DEFINE LCD_RSBIT 2 'defines the pin where RS line is connected to DEFINE LCD_EREG PORTD 'defines the port where E line is connected to DEFINE LCD_EBIT 3 'defines the pin where E line is connected 'DEFINE LCD_RWREG 0 'defines the port where R/W line is connected to (set to 0 if not used) 'DEFINE LCD_RWBIT 0 'defines the pin where R/W line is connected to (set to 0 if not used) DEFINE LCD_COMMANDUS 2000 'defines the delay after LCDOUT statement DEFINE LCD_DATAUS 200 'delay in micro seconds 'END of LCD DEFINES 'includes begin here INCLUDE "modedefs.bas" include "c:\pbp\samples\keypad.bas" 'end of includes 'Keypad code begins here DEFINE KEYPAD_ROW 4 ' 4 ROW keypad DEFINE KEYPAD_ROW_PORT PORTB ' ROW port = PORTB DEFINE KEYPAD_ROW_BIT 0 ' ROW0 = PORTB.4 DEFINE KEYPAD_COL 4 ' 4 COL keypad DEFINE KEYPAD_COL_PORT PORTB ' COL port = PORTB DEFINE KEYPAD_COL_BIT 4 ' COL0 = PORTB.0 DEFINE KEYPAD_DEBOUNCEMS 200 ' debounce delay = 200 mSec DEFINE KEYPAD_AUTOREPEAT 1 ' use auto-repeat feature 'end keypad code 'Main code begins here Pause 2000 ' Wait for LCD to startup start: 'read keypress variable @ READKEYPAD _myvar LOOKUP myvar,[0,"123A456B789C*0#D"],myvar 'use lookup table to diplay proper keypress datatx = myvar 'pass the variable to solve strange character problem lcdout datatx 'display the variable on the LCD lcdout $fe,1 'clear lcd screen 'receive section SerIn PORTC.7,T2400,DataRX 'receive data from other pic (16f887) and store as variable datarx LCDOUT datarx 'displays data received from serin datarx pause 2000 lcdout $fe,1 'clear lcd screen 'receive section ends 'transmit section 'send datarx(received data from toher pic) to pc serial port serout PORTC.6,T2400,["the key pressed or received value is ",datarx] 'SerOut PinNumber2,T2400,DataRec (FIXED!! pause 1000 'transmit section ends LCDout "end of transmission" lcdout $fe,1 'clear lcd screen goto start 'End of all code




Bookmarks