![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| dear all, m trying to make a project on interfacing rs232 with pic18f4550. m new to rs232 .cananybody please help me with some examples based on rs232 communication with pic18f. | |
| |
| | (permalink) | |
| Quote:
Code: list p=18F1320 include <p18f1320.inc> CONFIG OSC=INTIO2,WDT=OFF,MCLRE=ON,LVP=OFF,DEBUG=ON cblock 0x00 d1,d2,d3,dec1,dec2,count,num endc org 0x0000 init bsf OSCCON,IRCF2 ;set to 8MHz clock bsf OSCCON,IRCF1 bsf OSCCON,IRCF0 movlw 0x7f ;set PortA to all digital movwf ADCON1 clrf TRISA ;set PortA pins to output clrf LATA ;turn off LEDs clrf count movlw b'00010010' ;set PortB - RB4=RX=input movwf TRISB call rs_init bsf TXSTA,TXEN ;transmit enable main clrf TBLPTRH movlw text movwf TBLPTRL next_ch tblrd *+ movf TABLAT,W bz goagain call rs_send goto next_ch goagain incf num movf num,W call fix movf dec1,W call rs_send movf dec2,W call rs_send movlw 0x0d call rs_send movlw 0x0a call rs_send call delay call delay call delay call delay goto main ;Sends byte in W to RS232 rs_send movwf TXREG sdloop btfss TXSTA,TRMT goto sdloop return text db "RS232 on the 8 MHz clocked PIC 18F1320!",0x0d,0x0a,"It is the greatest!",0x0d,0x0a,0x0a rs_init movlw 0x0c ;set for 9600 baud @ 8MHz clock movwf SPBRG bcf TXSTA,BRGH ;clear Baud Rate Select Bit (low speed) bcf BAUDCTL,BRG16 ;select 8-bit baud rate generator bcf TXSTA,SYNC ;asynchronous mode bsf RCSTA,SPEN ;enable serial port return ;********************************************************* ;*fix - subroutine takes byte passed in W - splits it into ;*two ascii bytes in dec1 and dec2, representing decimal digits. fix movwf dec2 ;put number in dec2 clrf count ;count = 0 movlw 10 ;W = 10 tens subwf dec2,F ;subtract 10 from number btfsc STATUS,C ;check if result <10 goto again ;no, go again movf count,W ;yes, put count in W addlw 0x30 ;add $30 to make it an ASCII number movwf dec1 ;and store it in dec1 movf dec2,W ;get remainder (2nd digit) addlw 10 ;put the last subtract back addlw 0x30 ;add $30 to make it ASCII movwf dec2 ;store it back in dec2 return ;and return again incf count,F ;increment count goto tens ;go again delay movlw 0x01 movwf d1 movlw 0x7f movwf d2 movlw 0x01 movwf d3 delay_0 decfsz d1,f goto $+6 decfsz d2,f goto $+6 decfsz d3,f goto delay_0 return end
__________________ ========================= Futz's Microcontrollers & Robotics ========================= | ||
| |
| | (permalink) | |
| Quote:
I would recommend these projects: http://www.sixca.com/eng/articles/usbdaq/index.html http://www.embedds.com/simple-usb-to...on-pic18f2455/ http://www.piccoder.co.uk/content/view/42/26/http://www.piccoder.co.uk/content/view/42/26/ Good luck, Ferenc | ||
| |
| | (permalink) |
| Dear frnds this code i tried out for usart with pic18f4550 but m geeting the error which i have decribed below ..please help out.m using mplabc18 compiler #include <p18f4550.h> #include <usart.h> void rx_handler (void); #define BUF_SIZE 25 #pragma idata bigdata char data[11][BUF_SIZE+1] = { { "String #0\n\r" }, { "String #1\n\r" }, { "String #2\n\r" }, { "String #3\n\r" }, { "String #4\n\r" }, { "String #5\n\r" }, { "String #6\n\r" }, { "String #7\n\r" }, { "String #8\n\r" }, { "String #9\n\r" }, { "Invalid key (0-9 only)\n\r" } }; #pragma idata #pragma code rx_interrupt = 0x8 void rx_int (void) { _asm goto rx_handler _endasm } #pragma code #pragma interrupt rx_handler void rx_handler (void) { unsigned char c; /* Get the character received from the USART */ c = ReadUSART(); if (c >= '0' && c <= '9') { c -= '0'; /* Display value received on LEDs */ PORTB = c; putsUSART (data[c]); } else { putsUSART (data[10]); /* Display value received on LEDs */ PORTB = c; } /* Clear the interrupt flag */ PIR1bits.RCIF = 0; } void main (void) { /* Configure all PORTB pins for output */ TRISB = 0; OpenUSART (USART_TX_INT_OFF & USART_RX_INT_ON & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_HIGH, 103); putrsUSART ( (const far rom char *)"\n\rEnter a digit 0-9!\n\r"); RCONbits.IPEN = 1; IPR1bits.RCIP = 1; INTCONbits.GIEH = 1; while (1) ; } the linker file added is // File: 18f4550.lkr // Sample linker script for the PIC18F4550 processor LIBPATH . FILES c018i.o FILES clib.lib FILES p18f4550.lib CODEPAGE NAME=vectors START=0x0 END=0x29 PROTECTED CODEPAGE NAME=page START=0x2A END=0x7FFF CODEPAGE NAME=idlocs START=0x200000 END=0x200007 PROTECTED CODEPAGE NAME=config START=0x300000 END=0x30000D PROTECTED CODEPAGE NAME=devid START=0x3FFFFE END=0x3FFFFF PROTECTED CODEPAGE NAME=eedata START=0xF00000 END=0xF000FF PROTECTED ACCESSBANK NAME=accessram START=0x0 END=0x5F DATABANK NAME=gpr0 START=0x60 END=0xFF DATABANK NAME=gpr1 START=0x100 END=0x1FF DATABANK NAME=gpr2 START=0x200 END=0x2FF DATABANK NAME=gpr3 START=0x300 END=0x3FF DATABANK NAME=usb4 START=0x400 END=0x4FF PROTECTED DATABANK NAME=usb5 START=0x500 END=0x5FF PROTECTED DATABANK NAME=usb6 START=0x600 END=0x6FF PROTECTED DATABANK NAME=usb7 START=0x700 END=0x7FF PROTECTED ACCESSBANK NAME=accesssfr START=0xF60 END=0xFFF PROTECTED SECTION NAME=CONFIG ROM=config STACK SIZE=0x100 RAM=gpr3 error which m getting while complilation is Error - section 'bigdata' can not fit the section. Section 'bigdata' length=0x0000011e Errors : 1 | |
| |
| | (permalink) |
| Getting back to basics, if you need to hook the 4550 up to a PC make sure you are using a level shifter such as a MAX232 or similar. | |
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| Title | Starter | Forum | Replies | Latest |
| how send serial data with PIC | HCT-Pirate | Micro Controllers | 7 | 3rd February 2008 05:27 PM |
| serial communication from PIC to PC | flemmard | Electronic Projects Design/Ideas/Reviews | 10 | 11th September 2007 12:07 PM |
| Need help badly on Inchworm and MPLAB | thushy | Micro Controllers | 14 | 11th March 2007 07:05 PM |
| serial communication between two pic with RF modules | amindzo | Micro Controllers | 8 | 16th August 2006 04:59 PM |
| Serial communication problem | tbrown | Micro Controllers | 12 | 13th February 2004 11:32 AM |