|
|
View previous topic :: View next topic |
Author |
Message |
paef
Joined: 22 Apr 2006 Posts: 2
|
Serial communication tutorial? |
Posted: Sat Apr 22, 2006 8:21 am |
|
|
Hi, i have a PIC16F84 that i'm trying to get communicate with my computer.. It should currently run at 4mhz with this crystal i use..
So i wonder if there is any good tutorials out there that show how you are suppose to communicate with a computer through the serialport? Tried google but couldn't find any good...
This code is what i use today, but only get scramble tokens to the computer, #&%"!&Y¤##%"??`"#!% something like that.. I try to send hello world from pic processor...
Also a good developer would be nice, i am currently using a program called Cc5x, this prog doesn't seem to work with code i find on the net..
ie the #use stuff doesn't seem to be in it
Code: |
#include "16F84.h"
/* Circuitprogrammer Configuration: */
#pragma config |= 0x3ff1
#define ON 1
#define OFF 0
#pragma bit lightdiode @ RB1
#pragma bit button @ RB0
bit putchar( char ); /* function prototype */
char text1( char ); /* function prototype */
void delay( char millisec)
/*
Delays a multiple of 1 milliseconds at 4 MHz
using the TMR0 timer
*/
{
OPTION = 2; /* prescaler divide by 8 */
do {
TMR0 = 0;
while ( TMR0 < 125) /* 125 * 8 = 1000 */
;
} while ( -- millisec > 0);
}
void main( void)
{
TRISB = 0b11111100; /* RB0 out, RB1 out */
int i;
lightdiode=ON;
while (1) {
lightdiode=ON;
for(i=0; putchar( text1(i)); i++) ;
}
}
char text1( char x)
{
skip(x); /* internal function CC5x. */
#pragma return[] = "hello, world" '\r' '\n' '\0'
}
/* ECHOS CHARACTER TO PIN */
bit putchar( char d_out ) /* sends one char */
{
char bitCount, ti;
/* One start bit, one stop bit, 8 data bit, no parity = 10 bit. */
/* Baudrate: 9600 baud => 104.167 usec. per bit. */
if(d_out == '\0') return 0; /* refuse to send "end of string" */
PORTB.0 = 0; /* set startbit */
for ( bitCount = 10; bitCount > 0 ; bitCount-- )
{
/* delay one bit 104 usec at 4 MHz (5+30*3-1+1+9=104) */
ti = 30; do ; while( --ti > 0); nop();
Carry = 1; /* stopbit */
d_out = rr( d_out ); /* Rotate Right through Carry */
PORTB.0 = Carry;
}
return 1; /* all done */
}
|
|
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Sat Apr 22, 2006 8:47 am |
|
|
This forum belongs to CCS.
The posted code was written for another compiler that you actually are using,
so you are looking for help in the wrong forum.
CCS C Compiler has built in functions that enable you to write true C code,
not pseudo-code.
The following code does the same as your code.
Code: |
#include <16F84.H>
#fuses XT,NOWDT,NOPROTECT,PUT
#use delay (clock=4000000)
#use rs232(baud=9600, xmit=PIN_B1, rcv=PIN_B0)
void main()
{
while(1)
{
printf("Hello World");
delay_ms(500);
}
}
|
Humberto |
|
|
Guest
|
|
Posted: Sat Apr 22, 2006 9:04 am |
|
|
Oh, tnx..
will try this complier then, seems better! |
|
|
paef
Joined: 22 Apr 2006 Posts: 2
|
|
Posted: Sat Apr 22, 2006 9:12 am |
|
|
Code: |
#pragma chip PIC16F84, core 14, code 1024, ram 12 : 0x4F
|
Invalid pre-processor directive i get from that one.... are there diffrent headerfiles for this complier, and where can i find them in that case?
edit:
BAAH, do you realy have to buy it to get access to that file? its a schoolthing, will probably use it twice.. and cost was abit to much for me when i only will use it once or twice? 125 dollars ? :/
tnx.. |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Sat Apr 22, 2006 10:27 am |
|
|
If you are going to use it only for school things, another choice you have is to download the demo-version wich is free.
It only support 3 type of microcontroller, so you would buy the PIC16F877 (~$10,00.)
You can get the demo-version here:
http://www.ccsinfo.com/content.php?page=compdemo
Humberto |
|
|
rberek
Joined: 10 Jan 2005 Posts: 207 Location: Ottawa, Canada
|
|
Posted: Sat Apr 22, 2006 11:58 am |
|
|
That code looks like Microchip's C18 code.
They have a student version of their compiler, which is free, as welll. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|