tomas
Member level 1
- Joined
- Dec 16, 2012
- Messages
- 41
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Activity points
- 1,553
char receive;
void main() {
TRISD = 0x00;
PORTD = 0x00;
UART1_Init(2400);
Delay_ms(100);
while(1) {
PORTD = 0;
Delay_ms(100);
if (UART1_Data_Ready() == 1) {
receive = UART1_Read();
if(receive == 0x01)
{
PORTD.F0 = 1;
PORTD.F2 = 1;
Delay_ms(2000);
}
if(receive == 0x08)
{
PORTD.F1 = 1;
PORTD.F3 = 1;
Delay_ms(2000);
}
if(receive == 0x06)
{
PORTD.F0 = 1;
PORTD.F3 = 1;
Delay_ms(2000);
}
if(receive == 0x05)
{
PORTD.F1 = 1;
PORTD.F2 = 1;
Delay_ms(2000);
}
}}}
void main() {
TRISB=0xFF;
PORTB=0x00;
UART1_Init(2400);
Delay_ms(100);
while(1) {
if (UART1_Tx_Idle() == 1) {
if (PORTB.RB2==1){
UART1_Write(0x05);
}
if (PORTB.RB3==1){
UART1_Write(0x06);
}
if (PORTB.RB4==1){
UART1_Write(0x01);
}
if (PORTB.RB5==1){
UART1_Write(0x08);
}
}
}}
char receive;
double volt = 0;
unsigned char svolt[23];
void main() {
TRISA = 0xFF;
PORTA = 0x00;
ADCON0 = 0b01000000;
ADCON1 = 0b10001110;
TRISC.RC6 = 1;
TRISC.RC7 = 1;
TRISB = 0x00;
PORTB.RB0 = 1;
TRISD = 0x00;
PORTD = 0x00;
// TRISC = 0x80;
UART1_Init(2400);
Delay_ms(100);
while(1) {
volt = ADC_Read(0);
volt = volt * 0.0048875864003809; //approx 5V/1023
PORTD = 0;
// Delay_ms(100);
if (UART1_Tx_Idle() == 1) {
if((volt >= 1.75) && (volt < 1.85)) {
UART1_Write(0x01);
}
else if((volt >= 1.85) && (volt < 1.9)) {
UART1_Write(0x02);
}
else if((volt >= 1.9) && (volt < 1.95)) {
UART1_Write(0x03);
}
else if((volt >= 1.95) && (volt <= 2.3)) {
UART1_Write(0x04);
}
else
{
// TXSTA=0b00000100;
if (UART1_Data_Ready() == 1) {
receive = UART1_Read();
if(receive == 0x01)
{
PORTD.F0 = 1;
PORTD.F2 = 1;
Delay_ms(500);
}
if(receive == 0x08)
{
PORTD.F1 = 1;
PORTD.F3 = 1;
Delay_ms(500);
}
if(receive == 0x06)
{
PORTD.F0 = 1;
PORTD.F3 = 1;
Delay_ms(500);
}
if(receive == 0x05)
{
PORTD.F1 = 1;
PORTD.F2 = 1;
Delay_ms(500);
}
}}}
}}
#define LED1 PORTD.F0
#define LED2 PORTD.F1
#define LED3 PORTD.F2
#define LED4 PORTD.F3
char pirmas;
void main() {
TRISD = 0x00;
PORTD = 0x00;
// TRISC.RB3 = 0x00;
// PORTC.RB3 = 1;
TRISB=0xFF;
PORTB=0x00;
UART1_Init(2400);
Delay_ms(100);
while(1) {
if (UART1_Data_Ready() == 1) {
pirmas = UART1_Read();
if(pirmas == 0x01)
{
LED1 = 1;
Delay_ms(500);
}
LED1 = 0;
if(pirmas == 0x02)
{ LED1 = 1;
LED2 = 1;
Delay_ms(500);
}
LED1=0;
LED2 = 0;
if(pirmas == 0x03)
{
LED1 = 1;
LED2 = 1;
LED3 = 1;
Delay_ms(500);
}
LED1 = 0;
LED2 = 0;
LED3 = 0;
if(pirmas == 0x04)
{
LED1 = 1;
LED2 = 1;
LED3 = 1;
LED4 = 1;
Delay_ms(500);
}
LED1 = 0;
LED2 = 0;
LED3 = 0;
LED4 = 0;
}
else{
if (UART1_Tx_Idle() == 1) {
if (PORTB.RB2==1){
UART1_Write(0x05);
}
if (PORTB.RB3==1){
UART1_Write(0x06);
}
if (PORTB.RB4==1){
UART1_Write(0x01);
}
if (PORTB.RB5==1){
UART1_Write(0x08);
}
}
}}
}
I need to turn on only receiver, transmitter should be off, ten receiver off, transmitter on. How can I do this switching?
in other words, I need to put tx to sleep
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?