Jump to content

Recommended Posts

Hi,

 

 

who can tell me, why the following code for 16F876A does not work?

 

//---------------------------------------------------------------
// Test programm for simple output via USART (polling)
//---------------------------------------------------------------
#include <system.h>

// #define SOFTWAREEMULATEDSUPPORT

// #include "my_rs232_driver.h"
// #include <rs232_driver.h>

#pragma CLOCK_FREQ 8000000


//Writes Character to Serial Port
void OutTx(unsigned char cByte)
{
 while(!pir1.TXIF) 	 // pie1.TXIE Wait for interrupts to finish last message
   continue;    
   
 txreg = cByte;  
}



void main(void)
{
 char cLoop = 0;
 
 adcon1 = 0x06; 	// set all pins as digital inputs
 trisc  = 0x80; 	// Rx In
 portc  = 0x00;
 
 spbrg  = 51; 		// 2400 Baud @ 8 MHz
 txsta.BRGH = 0;
 txsta.SYNC = 0;
 rcsta.SPEN = 1; 	// Serial Port Enable ... RC6 for Tx and RC7 for RX 
 pie1.TXIE  = 0; 	 // Polling ... No Interrupt Enable 
 txsta.TXEN = 1;	 // Transmission Enable

 while(1)
 { 
   cLoop++;
   // putc(cLoop);
   OutTx(cLoop);
   delay_ms(1);
 }
}

 

Thanks

 

 

Turhan

Link to post
Share on other sites
From the PIC16F87X datasheet:

 

Flag bit TXIF is set when enable bit TXEN

is set. TXIF is cleared by loading TXREG.

 

You are correct. I am an idiot.

 

I did take a closer look at the sample code and run it on a real part.

 

The _CONFIG is not setup so the defaults caused my 16F876A to run with the watchdog enabled and the oscillator mode set to RC.

 

Adding:

 

#pragma DATA _CONFIG, _CP_OFF & _WRT_ENABLE_ON & _CPD_OFF & _LVP_OFF & _BODEN_ON & _PWRTE_OFF & _WDT_OFF & _HS_OSC

 

Fixed these issue and the code runs as expected.

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...