Промених целия код и компилатора включително.Сега работи и на Proteus sim и на реален pic18.Proteus след Reset ми позволява отново да въвеждам символ и диода свети.Това обаче не се случваше с предишния код ,дори и след като бе модифициран!Да не говорим,че в реален pic изобщо диода не светваше.За съжаление функцията Delay10KTCYx(250);не гаси диода.Сега ще се опитвам да го гася чрез Timer0.Това е новият код:
/* Main.c file generated by New Project wizard
*
* Created: 26.08. 2014
* Processor: PIC18F2550
* Compiler: MPLAB XC8
*/
#include <p18f2550.h>
#include <xc.h>
#include <delays.h>
#include <portb.h>
#include <usart.h>
#include <stdio.h>
#include <stdlib.h>
//** CONFIGURATION ******************************************************************************************
#pragma config PLLDIV = 5 // (20 MHz crystal)
#pragma config CPUDIV = OSC1_PLL2
#pragma config USBDIV = 2 // Clock source from 96MHz PLL/2
#pragma config FOSC = HSPLL_HS
#pragma config FCMEN = OFF
#pragma config IESO = OFF
#pragma config PWRT = OFF
#pragma config BOR = ON
#pragma config BORV = 3
#pragma config VREGEN = ON // USB Voltage Regulator
#pragma config WDT = OFF
#pragma config WDTPS = 32768
#pragma config MCLRE = ON
#pragma config LPT1OSC = OFF
#pragma config PBADEN = OFF
// #pragma config CCP2MX = ON
#pragma config STVREN = ON
#pragma config LVP = OFF
// #pragma config ICPRT = OFF // Dedicated In-Circuit Debug/Programming
#pragma config XINST = OFF // Extended Instruction Set
#pragma config CP0 = OFF
#pragma config CP1 = OFF
// #pragma config CP2 = OFF
// #pragma config CP3 = OFF
#pragma config CPB = OFF
// #pragma config CPD = OFF
#pragma config WRT0 = OFF
#pragma config WRT1 = OFF
// #pragma config WRT2 = OFF
// #pragma config WRT3 = OFF
#pragma config WRTB = OFF // Boot Block Write Protection
#pragma config WRTC = OFF
// #pragma config WRTD = OFF
#pragma config EBTR0 = OFF
#pragma config EBTR1 = OFF
// #pragma config EBTR2 = OFF
// #pragma config EBTR3 = OFF
#pragma config EBTRB = OFF
//******************************DECLARATION OF GLOBAL VARIABLES*************************
char data;
//******************************Declaration of Function Prototype***************************
char ReadUSART( void );
void WriteUSART( char data );
//****************************************************************************************
// LED Setings:
#define setpin() TRISB = 0; // Set all pins to output
#define LED1 LATBbits.LATB0 // RB1
#define LED1_on()LED1 = 1; // High
#define LED1_off()LED1 = 0; // Low
//***************************************************************
void main(void)
{
setpin();
// configure USART
OpenUSART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW & USART_ADDEN_OFF, 32);
/*
USART_TX_INT_OFF = 0b00000000 // Transmit interrupt off
USART_RX_INT_OFF = 0b00000000 // Receive interrupt off
USART_SYNCH_MODE = 0b00000000 // Asynchronous mode
USART_EIGHT_BIT = 0b11111101 // 8-bit data
USART_CONT_RX = 0b00001000 // Continuous reception
USART_BRGH_LOW = 0b11111111 // Baud rate
USART_ADDEN_OFF = 0b11011111
SPBRG = 32
*/
baudUSART(BAUD_IDLE_CLK_HIGH & BAUD_8_BIT_RATE & BAUD_WAKEUP_OFF & BAUD_AUTO_ON & BAUD_IDLE_RX_PIN_STATE_HIGH & BAUD_IDLE_TX_PIN_STATE_HIGH);
/*
BAUD_IDLE_CLK_HIGH = 0 // Idle state for clock is a high level
BAUD_8_BIT_RATE = 0b00000000 // 8-bit baud generation rate
BAUD_WAKEUP_OFF = 0b00000000 // RX pin not monitored
BAUD_IDLE_RX_PIN_STATE_HIGH = 0b11011111 // Idle state for RX pin is high level
BAUD_IDLE_TX_PIN_STATE_HIGH = 0b11101111 // Idle state for TX pin is high level
*/
/* To set up USART */
RCSTAbits.SPEN = 1; // Serial port is enabled
PORTCbits.RC7 = 1; // Input coming from Rx pin
PORTCbits.RC6 = 0; // Output meaning write to Tx pin
TXSTA = 0b00100000; // Configurations for transmit register
RCSTA = 0b10010000; // Configurations for receive register
BAUDCON = 0b00000000;
//******************************Configuration TIMER0****************************************
unsigned int counter = 0; // Variable that holds timer overflow count
// Initialize Timer0
T0CON = 0b11000111;
//T0CONbits.TMR0ON = 1; // Enables Timer0
//T0CONbits.T08BIT = 1; // Timer0 is configured as an 8-bit timer/counter
//T0CONbits.T0CS = 1; // Select timer module with external clock
//T0CONbits.PSA = 0; // Assignet prescaler to Timer0
//T0CONbits.T0PS2 = 1; // Timer0 Prescaler Select bits
//T0CONbits.T0PS1 = 1; // Increment overy 256
//T0CONbits.T0PS0 = 1;
//**********************************************************************************************
while(1) // Create Loop
{
while(DataRdyUSART()); // Is data available in the read buffer?
PORTB = ReadUSART(); // Read a byte out of the USART receive buffer and send it to PORTB /
if(ReadUSART()=='1') // If the received data is equal to the '1'
{
LED1_on(); // LED blinking
Delay10KTCYx(250); // Това не работи
LED1_off(); // LED off
}
}
}