Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 29th September 2007, 08:11 AM   (permalink)
Default TX_test program in PIC C

hi all,
The code below is not working...Can anyone advice on this.I'm using PIC16f877.

Code:
#include <pic1687x.h>
#include <pic.h>

// Transmitter test program


void main() {
    TRISC = 0x00 ; //portC as output
	SPBRG = 129;	// Set the baud rate to 9.6k
	BRGH = 1;		// Set high baud rate 
	SYNC = 0;		// Set asynchronous 
	SPEN = 1;		// Enable serial port pins 
	SREN=0;	         
	TX9 = 0;		// Disable 9 bit transmission 
	TXIE = 0;		// Disable tx interrupts 
	RCIE = 0;		// Disable rx interrupts 
	TXEN  = 0;      //reset the transmitter
	TXEN = 1;		// Enable the transmitter

	while(1) {
	    TXEN  = 1;
		while(!TXIF) {	// Checks if the transmit flag is down 
			continue;
		}
		TXREG = 0b01010101;
	}
}
Thanks
flemmard is offline  
Old 29th September 2007, 02:12 PM   (permalink)
Default

TX and RX have to be set to input for the UART to work. You should also write to TXREG and then wait for TXIF to be set.

Mike.
Pommie is offline  
Old 29th September 2007, 03:20 PM   (permalink)
Default

Quote:
Originally Posted by Pommie
TX and RX have to be set to input for the UART to work. You should also write to TXREG and then wait for TXIF to be set.

Mike.
Hi, thanks for your reply ! Can you please send me your code if you have some sample?
flemmard is offline  
Old 29th September 2007, 03:28 PM   (permalink)
Default

I only use asm on 16F pics but I would guess it would be something like,

Code:
#include <pic1687x.h>
#include <pic.h>

// Transmitter test program


void main() {
	TRISC = 0xc0 ; //portC as output
	SPBRG = 129;	// Set the baud rate to 9.6k
	BRGH = 1;		// Set high baud rate 
	SYNC = 0;		// Set asynchronous 
	SPEN = 1;		// Enable serial port pins 
	SREN=0;	         
	TX9 = 0;		// Disable 9 bit transmission 
	TXIE = 0;		// Disable tx interrupts 
	RCIE = 0;		// Disable rx interrupts 
	TXEN  = 0;      //reset the transmitter
	TXEN = 1;		// Enable the transmitter

	while(1) {
		TXEN  = 1;
		TXREG = 0b01010101;
		while(!TXIF); 	// Checks if the transmit flag is down 
	}
}
Mike.
Pommie is offline  
Old 29th September 2007, 04:56 PM   (permalink)
Default

I am compiling a Problem-Issue Verses Effort-Issue report.

I will incorportate this example as an Effort-Issue.
donniedj is offline  
Old 30th September 2007, 07:32 AM   (permalink)
Default

Quote:
Originally Posted by Pommie
I only use asm on 16F pics but I would guess it would be something like,

Code:
#include <pic1687x.h>
#include <pic.h>

// Transmitter test program


void main() {
	TRISC = 0xc0 ; //portC as output
	SPBRG = 129;	// Set the baud rate to 9.6k
	BRGH = 1;		// Set high baud rate 
	SYNC = 0;		// Set asynchronous 
	SPEN = 1;		// Enable serial port pins 
	SREN=0;	         
	TX9 = 0;		// Disable 9 bit transmission 
	TXIE = 0;		// Disable tx interrupts 
	RCIE = 0;		// Disable rx interrupts 
	TXEN  = 0;      //reset the transmitter
	TXEN = 1;		// Enable the transmitter

	while(1) {
		TXEN  = 1;
		TXREG = 0b01010101;
		while(!TXIF); 	// Checks if the transmit flag is down 
	}
}
Mike.

Hi , can you send me your asm code to to test my tx ?
I understand that i can add that asm code directly to my C for compilation
Thanks in advance
flemmard is offline  
Old 30th September 2007, 12:21 PM   (permalink)
Default

Quote:
Originally Posted by flemmard
Hi , can you send me your asm code to to test my tx ?
I understand that i can add that asm code directly to my C for compilation
Thanks in advance
You can check my RS232 PIC tutorial for assembler code.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now  
Reply

Bookmarks

Thread Tools
Display Modes



Similar Threads
Title Starter Forum Replies Latest
First Program in assembly, And Programmer Inchworm. Ayne Micro Controllers 10 9th March 2007 08:27 PM
program for writing and testing circuits luca-deltodesco General Electronics Chat 3 13th August 2006 11:17 AM
little help with my program please - simple count loop kud0s Micro Controllers 5 7th July 2005 10:40 PM
PicBasic Keypad program Sora Micro Controllers 0 20th April 2004 08:02 PM
Program Verify on JMD with ic-prog monkeyxp Micro Controllers 2 2nd November 2003 12:56 PM



All times are GMT. The time now is 09:50 PM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker