dear ckshivaram
yes that exacly whats iam trying to do, each serial data value will control separte output pin
in summary
tcp/ip command will convert to serial
''0000 0001'' switch on RB1 "Relay 1"
''0000 0010'' switch swich off RB1 "Relay 1"
and so on for the other realys
can you help me in understanding some issues.
---------- Post added at 13:23 ---------- Previous post was at 13:16 ----------
dear wp100
i started writing my prgram in assembly bu i stacked in reading the 8bit data from the RCREG regersty how can i write instraction to do the following:
read the 8bit data in RCREG and if it equal to "1" switch on RB1 to high. ??
and i dont need to use RS232 circuit because iam using embedded serial uart card it will send and receive 3.3V ttl serial (that mean it can communicate directly with my pic but in between i will use a logic converter 3.3V to 5 V and opposite).
waiting ur replay
so -
sending 00000101 will turn on relays 1 and 3
sending 00000001 will turn off relay 3 but leave relay1 on
sending 00000110 will turn relay 2 and 3 on, relay 0 off.
This is all achieved by simply copying RCREG to PORTB
You have Cleared the Ports but you needs to set their Direction ie Inputs or Outputs with the respective TRIS instruction"
yes i will go through the setup and i will do itAlso see the Datasheet PORTA section for the code example of how to ensure you set the Ports to Digital rather than the default Analogue
Your Baud rate set up, a bit unusual in 9 bits ? - 8 data bits + 1 stop bit is more often used, or have you added both together ?
here i have lack of knowlege since this is my first time working on uart i dont know how to write instrucation to recive the data and then write it on w then on port B if you have more examples i will appriate your help.After that you have just said read the RCREG file, but you have not told it to receive any data !
;Serial routines - write received bytes on PORTB
LIST p=16F877a ;tell assembler what chip we are using
include "P16F877a.inc" ;include the defaults for the chip
ERRORLEVEL 0, -302 ;suppress bank selection messages
__config 0x393A ;sets the configuration settings (oscillator type etc.)
cblock 0x20 ;start of general purpose registers
count ;used in looping routines
endc
org 0x0000
BANKSEL ADCON1
movlw 0x06
movwf ADCON1
BANKSEL PORTB ;turn analogue inputs off
Initialise
clrf PORTB
call SER_INIT ;initialise serial port
Loop call Rcv_RS232
goto Loop
;USART Serial routines
SER_INIT
BSF STATUS, RP0 ;select bank 1
MOVLW d'25' ;9600 baud @ 4 Mhz
MOVWF SPBRG
MOVLW b'00100100' ;brgh = 1
MOVWF TXSTA ;enable Async Transmission, set brgh
BCF STATUS, RP0 ;select bank 0
MOVLW b'10010000'
MOVWF RCSTA ;enable Async Reception
RETURN
Rcv_RS232 BTFSS PIR1, RCIF ; check for received data and shift to portB
GOTO Rcv_RS232
MOVF RCREG, W
MOVWF PORTB
RETURN
;End of serial routines
end
org 0x0000
BANKSEL ADCON1
movlw 0x06 ;turn analogue inputs off
movwf ADCON1
BANKSEL PORTB
Initialise
clrf PORTB
BANKSEL TRISB ; SET TRISB TO DIGITAL OUTPUTS
CLRF TRISB
BANKSEL 0
LIST p=16F877a ;tell assembler what chip we are using
include "P16F877a.inc" ;include the defaults for the chip
__config _CP_OFF & _XT_OSC & _WDT_OFF & _PWRTE_ON & _LVP_OFF & _BODEN_ON
CBLOCK 0x20 ;Declare variable address
dataL
ENDC
;
; -----------
; INITIALIZE
; -----------
;
org 0x0000
goto Start ; Jump to Start
org 0x0004
Start movlw 0x00
movwf PORTA ; Initialize port A
movlw 0x00
movwf PORTB ; Initialize port B
movlw 0x40
movwf PORTC ; Initialize port C
movlw 0x00
movwf PORTD ; Initialize port D
bsf STATUS,RP0 ; Bank 1
movlw b'00000000'
movwf TRISA ; All pins port A output (lcd display data)
movlw b'00000000'
movwf TRISB ; All pins port B output (Controlled Relays)
movlw b'10000000'
movwf TRISC ; All pins port C output except RC7/RX and RC0 for local check
movlw b'10000001'
movwf TRISD ; All pins port D output except RD (lcd display control and keypad inputs)
;
; -------------------------
; FUNCTION OF PORT A PINS
; -------------------------
;
movlw 0x06 ; All pins digital I/O
movwf ADCON1
;
; --------------------------------------------
; SET BAUD RATE TO COMMUNICATE WITH UART CARD
; --------------------------------------------
; Boot Baud Rate = 9600, 8 bit data ,No Parity, 1 Stop Bit
;
movlw D'25' ; 9600 baud rate
movwf SPBRG
movlw b'01100100' ; brgh = 1
movwf TXSTA ; enable Async Transmission, set brgh
bcf STATUS,RP0 ; Bank 0
movlw b'11010000' ; enable Async Reception
movwf RCSTA
;
; ------------------------------------
; PROVIDE A SETTLING TIME FOR START UP
; ------------------------------------
;
clrf dataL
settle decfsz dataL,F
goto settle
;
movf RCREG,W
movf RCREG,W
movf RCREG,W ; flush receive buffer
;
; ----------
; MAIN PROGRAM
; ----------
;
Main
call Check_status ;check if local control panel on or off
Control_Remote
call Receive_data ; wait for data
movwf PORTB ; Relays active
movwf TXREG ; echo data back to sender
call Send_data ; wait until finished sending
goto Main
;
; ----------------------------
; RECEIVE DATA FROM UART CARD
; ----------------------------
;
Receive_data btfss PIR1,RCIF ; check for received data
goto Receive_data
movf RCREG,W
return
;
; ------------------------------------
; WAIT UNTIL PIC IS FINISHED SENDING
; ------------------------------------
;
Send_data bsf STATUS,RP0 ; Bank 1
WaitHere btfss TXSTA,TRMT ; transmission is complete if high
goto WaitHere
bcf STATUS,RP0 ; Bank 0
return
;
; ---------------------------------------
; LOCAL USER CONTRL THROUGH LCD & KEYPAD
; ---------------------------------------
;
Check_status btfss PORTC,0
goto Control_Remote
goto Control_local
Control_local
bsf PORTC,1
goto Main
END
;
; ------------------------------------
; END OF THE CODE
; ------------------------------------
;
WaitHere btfss TXSTA,TRMT ; transmission is complete if high
my system udea is to connect the uart interface card 8N1 out/IN to pic16F877a UART out/IN
that why i need to make it on 9 bit since it is 8 bit with one stop
There are various data types and speeds used for RS232, I'm going to concentrate on the most common type in use, known as 8N1 - the 8 signifies '8 Data Bits', the N signifies 'No Parity' (can also be E 'Even Parity' or O 'Odd Parity'), the final 1 signifies '1 Stop Bit'. The total data sent consists of 1 start bit, 8 data bits, and 1 stop bit - giving a total of 10 bits.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?