>If you post yur values for the UART registers, we'll be able >to help you dounle-check them. >Jan-Erik. >PS. >I have used the UART on the 18F1320 using the 8 Mhz INTOSC >without any problems at all. Running with the default OSCTUNE >value h'00'. Now, the 18F1320 hase the "Enhanced USART", which >is a little different, the 18F1220/1320 has a "16-bit baud rate >generator" so you get, in general, baud rates closer to the >nominal speed. It can also run in "Compatible mode" with a 8-bit >baud rate generator. I'm not sure how I run mine, I just let >Olin's envoronment set everything up, I didn't even checked what >it had done since it all worked "out of the box" anyway :-) >But, if my 18F1320 was run in Compatible mode, it should have the >same setup for the UART as your 18F4320, I supose... ***************************************************** OK...I know I'll probably catch "you know what" from Olin because this is not relocateable code! I have downloaded his development tools and have just started to familiarize myself with them because I believe he is correct in his views concerning programming the PIC. Enough said, on to the code. Here is what I have done. This program, when set up for the 16F628 works fine on the 16F628. When configured for the 18F4320, I get exactly 33 null characters on reset and it will not respond to input via rs-232. My intentions were to have it send to the PC at reset "I AM ALIVE". From that point on it listens via polling (I know guys there are better ways...just a quick test here) for a "1" character. When a "1" is received it should send a CR/LF then "I AM ALIVE" again. BTW Olin's aspic_fix is GREAT! Code follows: Regards, Stephen D. Barnes LIST P=18F4320 ;directive to define processor #include ;processor specific variable definitions ;*************************************************************************** *** ;Configuration bits __CONFIG _CONFIG1H, _IESO_OFF_1H & _FSCMEN_OFF_1H & _INTIO2_OSC_1H __CONFIG _CONFIG2L, _PWRT_OFF_2L & _BOR_OFF_2L __CONFIG _CONFIG2H, _WDT_OFF_2H __CONFIG _CONFIG3H, _MCLRE_ON_3H & _PBAD_DIG_3H & _CCP2MX_C1_3H __CONFIG _CONFIG4L, _BKBUG_OFF_4L & _LVP_OFF_4L & _STVR_OFF_4L __CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L & _CP3_OFF_5L __CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H __CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L __CONFIG _CONFIG6H, _WRTC_OFF_6H & _WRTB_OFF_6H & _WRTD_OFF_6H __CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L __CONFIG _CONFIG7H, _EBTRB_OFF_7H ;*************************************************************************** *** ;Variable definitions CBLOCK 0x000 EXAMPLE ;example of a variable in access RAM dataL recdat ;variable used to hold RCREG data txdat ;variable used to hold TXREG data ENDC ORG 0x0000 goto Main ;go to start of main code ;*************************************************************************** *** ;Start of main program Main: ; -------------------------------- ; SET ANALOG/DIGITAL INPUTS PORT A ; -------------------------------- movlw 7 movwf CMCON ;CMCON=7 set comparators off ; ---------------- ; INITIALIZE PORTS ; ---------------- movlw b'10111111' movwf TRISA ;portA pins set per datasheet for USART movlw b'00000000' ;portB pins all output movwf TRISB ; ------------------------------------ ; SET BAUD RATE TO COMMUNICATE WITH PC ; ------------------------------------ ; Boot Baud Rate = 19200, No Parity, 1 Stop Bit movlw 25 ;19200 movwf SPBRG movlw b'00100100' ;brgh = high movwf TXSTA ;enable Async Transmission, set brgh movlw b'10010000' ;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 LOOP ; --------- call alive loop call receive movf recdat, W sublw "1" ; btfsc STATUS, Z ;if a "1" was received, call "echo" call echo ; goto loop ; ------------------------------------------- ; RECEIVE CHARACTER FROM RS232 AND STORE IN W ; ------------------------------------------- ; This routine does not return until a character is received. receive btfss PORTA, 0 btfss PIR1, RCIF ;(5) check for received data goto receive movf RCREG, W ;save received data in W movwf recdat return ; ------------------------------------------------------------- ; SEND CHARACTER IN W VIA RS232 AND WAIT UNTIL FINISHED SENDING ; ------------------------------------------------------------- send movwf TXREG ;send data in W TransWt WtHere btfss TXSTA, TRMT ;(1) transmission is complete if hi goto WtHere return alive ;sends "I AM ALIVE" via usart movlw "I" call send movlw " " call send movlw "A" call send movlw "M" call send movlw " " call send movlw "A" call send movlw "L" call send movlw "I" call send movlw "V" call send movlw "E" call send return echo movlw d'13' ;carriage return call send movlw d'10' ;line feed call send call alive return ;*************************************************************************** *** ;End of program END -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body