welcome
and I want to do a project with a pic18f4550 and fail to communicate with the computer, communication is via Bluetooth wireless module. want to order six stepper motors when sending characters from the PC. I did it I mikroc software in simulated in Proteus and everything seems to work only when the program does not work at all little, I tried to write the software in its spark mikroc a light character when sending a PC through the wireless module and UART that is not working. I would like help if possible, we used a 12 MHz crystal on the project.
attach code to the command and motors
/
/
///
#define TRUE 1
#define FALSE 0
#define coil_1 PORTD.F0
#define coil_2 PORTD.F1
#define coil_3 PORTD.F2
#define coil_4 PORTD.F3
#define sensor PORTA.F0
#define limist PORTA.F1
#define limidr PORTA.F2
char uart_rd;
int test_gripper(unsigned char mot,unsigned char dir) //testeaza conditiile de limitare
{ if ((mot==6) && (dir==1) && sensor) //nu mai strange gripperul (motor 6) daca ai senzorul de gripper
{UART1_Write_Text("Blocat");
UART1_Write(10);
UART1_Write(13);
return 0;
}
else
if ((mot==2) && (dir==0) && limist) //limiteaza directia (motor 2) pe cursa cu un senzor binar
return 0;
else
if ((mot==2) && (dir==1) && limidr) //limiteaza directia (motor 2) pe cursa cu un senzor binar
return 0;
else
return 1;//altfel permite actiunea...
}
void FWD_DIRECTION (unsigned char mot,unsigned char x,const int Vdelay) //x daca vrei mai multi pasi am pus sa faca numai unu
{
unsigned char c;
while (x > 0)
{
for (c=1; c < 5; c++)
if (test_gripper(mot,0))
{
if (c == 1)
{
coil_1 = TRUE;
coil_2 = TRUE;
coil_3 = FALSE;
coil_4 = FALSE;
Vdelay_ms(Vdelay);
}
if (c == 2)
{
coil_1 = TRUE;
coil_2 = FALSE;
coil_3 = FALSE;
coil_4 = TRUE;
Vdelay_ms (Vdelay);
}
if (c == 3)
{
coil_1 = FALSE;
coil_2 = FALSE;
coil_3 = TRUE;
coil_4 = TRUE;
Vdelay_ms (Vdelay);
}
if (c == 4)
{
coil_1 = FALSE;
coil_2 = TRUE;
coil_3 = TRUE;
coil_4 = FALSE;
Vdelay_ms (Vdelay);
}
}
x--;
}
}
void REV_DIRECTION (unsigned char mot,unsigned char x,const int Vdelay)
{
unsigned char c;
while (x > 0)
{
for (c=1; c < 5; c++)
if (test_gripper(mot,1))
{
if (c == 1)
{
coil_1 = TRUE;
coil_2 = TRUE;
coil_3 = FALSE;
coil_4 = FALSE;
Vdelay_ms (Vdelay);
}
if (c == 2)
{
coil_1 = FALSE;
coil_2 = TRUE;
coil_3 = TRUE;
coil_4 = FALSE;
Vdelay_ms (Vdelay);
}
if (c == 3)
{
coil_1 = FALSE;
coil_2 = FALSE;
coil_3 = TRUE;
coil_4 = TRUE;
Vdelay_ms (Vdelay);
}
if (c == 4)
{
coil_1 = TRUE;
coil_2 = FALSE;
coil_3 = FALSE;
coil_4 = TRUE;
Vdelay_ms (Vdelay);
}
}
x--;
}
}
void motor(unsigned char mot,unsigned char dir,int _Vdelay)
{
switch(mot)
{
case 1: PORTB=0b00000001;
break;
case 2: PORTB=0b00000010;
break;
case 3: PORTB=0b00000100;
break;
case 4: PORTB=0b00001000;
break;
case 5: PORTB=0b00010000;
break;
case 6: PORTB=0b00100000;
break;
/// etc .........
default:
break;
}
if(dir==0)FWD_DIRECTION(mot,1,_Vdelay);
if(dir==1)REV_DIRECTION(mot,1,_Vdelay);
PORTB=0;
PORTD=0;
}
void main() {
ADCON1 |= 0x0F; // Configure all ports with analog function as digital
CMCON |= 7; // Disable comparators
PORTA=0;
PORTB=0;
PORTD=0;
TRISB=0;
TRISD=0;
UART1_Init(9600); // Initialize UART module at 9600 bps
Vdelay_ms(100); // Wait for UART module to stabilize
UART1_Write_Text("Start");
UART1_Write(10);
UART1_Write(13);
while (1) { // Endless loop
if (UART1_Data_Ready()) { // If data is received,
uart_rd = UART1_Read(); // read the received data,
/// UART1_Write(uart_rd); // and send data via UART
switch(uart_rd)
{
case 'A': motor(1,0,100);
break;
case 'B': motor(1,1,100);
break;
case 'C': motor(2,0,100);
break;
case 'D': motor(2,1,100);
break;
case 'E': motor(3,0,100);
break;
case 'F': motor(3,1,100);
break;
case 'G': motor(4,0,100);
break;
case 'H': motor(4,1,100);
break;
case 'I': motor(5,0,100);
break;
case 'J': motor(5,1,100);
break;
case 'K': motor(6,0,100);
break;
case 'L': motor(6,1,100);
break;
default:
break;
//..................
}
}
}
}
uart 18f4550
General discussion on mikroC.
Author
Message
-
- Posts: 619
- Joined: 05 Jul 2008 06:05
- Location: Thailand
Re: uart 18f4550
#2 Post by Sobrietytest » 10 Nov 2010 11:39
I think the best thing for you to do is to write a short program to test the Bluetooth link, make sure it's working before you start working with the motor control.
Jump to
- NECTO Studio
- ↳ IDE
- ↳ IDE General
- ↳ IDE Beta Testing
- ↳ IDE Wish List
- ↳ ARM AI Compilers
- ↳ mikroC AI for ARM
- ↳ mikroC AI for ARM General
- ↳ mikroC AI for ARM Beta Testing
- ↳ mikroC AI for ARM Wish List
- ↳ PIC AI compilers
- ↳ mikroC AI for PIC
- ↳ mikroC AI for PIC General
- ↳ mikroC AI for PIC Beta Testing
- ↳ mikroC AI for PIC Wish List
- ↳ PIC32 AI Compilers
- ↳ mikroC AI for PIC32
- ↳ mikroC AI for PIC32 General
- ↳ mikroC AI for PIC32 Beta Testing
- ↳ mikroC AI for PIC32 Wish List
- ↳ dsPIC AI Compilers
- ↳ mikroC AI for dsPIC
- ↳ mikroC AI for dsPIC General
- ↳ mikroC AI for dsPIC Beta Testing
- ↳ mikroC AI for dsPIC Wish List
- ↳ AVR AI Compilers
- ↳ mikroC AI for AVR
- ↳ mikroC AI for AVR General
- ↳ mikroC AI for AVR Beta Testing
- ↳ mikroC AI for AVR Wish List
- ↳ Additional Software
- ↳ Visual TFT AI
- ↳ Visual TFT AI General
- ↳ Visual TFT AI Beta Testing
- ↳ Visual TFT AI Wish List
- PRO Compilers
- ↳ PIC PRO Compilers
- ↳ PIC Compilers General
- ↳ mikroC PRO for PIC
- ↳ mikroC PRO for PIC General
- ↳ mikroC PRO for PIC Beta Testing
- ↳ mikroC PRO for PIC Wish List
- ↳ mikroBasic PRO compiler for PIC
- ↳ mikroBasic PRO for PIC General
- ↳ mikroBasic PRO for PIC Beta Testing
- ↳ mikroBasic PRO for PIC Wish List
- ↳ mikroPascal PRO for PIC
- ↳ mikroPascal PRO for PIC General
- ↳ mikroPascal PRO for PIC Beta Testing
- ↳ mikroPascal PRO for PIC Wish List
- ↳ dsPIC PRO Compilers
- ↳ dsPIC Compilers General
- ↳ mikroC PRO for dsPIC30/33 and PIC24
- ↳ mikroC PRO for dsPIC30/33 and PIC24 General
- ↳ mikroC PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroC PRO for dsPIC30/33 and PIC24 Wish List
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 General
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroBasic PRO for dsPIC30/33 and PIC24 Wish List
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 General
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroPascal PRO for dsPIC30/33 and PIC24 Wish List
- ↳ PIC32 PRO Compilers
- ↳ PIC32 Compilers General
- ↳ mikroC PRO for PIC32
- ↳ mikroC PRO for PIC32 General
- ↳ mikroC PRO for PIC32 Beta Testing
- ↳ mikroC PRO for PIC32 Wish List
- ↳ mikroBasic PRO for PIC32
- ↳ mikroBasic PRO for PIC32 General
- ↳ mikroBasic PRO for PIC32 Beta Testing
- ↳ mikroBasic PRO for PIC32 Wish List
- ↳ mikroPascal PRO for PIC32
- ↳ mikroPascal PRO for PIC32 General
- ↳ mikroPascal PRO for PIC32 Beta Testing
- ↳ mikroPascal PRO for PIC32 Wish List
- ↳ AVR PRO Compilers
- ↳ AVR Compilers General
- ↳ mikroC PRO for AVR
- ↳ mikroC PRO for AVR General
- ↳ mikroC PRO for AVR Beta Testing
- ↳ mikroC PRO for AVR Wish List
- ↳ mikroBasic PRO compiler for AVR
- ↳ mikroBasic PRO for AVR General
- ↳ mikroBasic PRO for AVR Beta Testing
- ↳ mikroBasic PRO for AVR Wish List
- ↳ mikroPascal PRO for AVR
- ↳ mikroPascal PRO for AVR General
- ↳ mikroPascal PRO for AVR Beta Testing
- ↳ mikroPascal PRO for AVR Wish List
- ↳ FT90x PRO Compilers
- ↳ FT90x Compilers General
- ↳ mikroC PRO for FT90x
- ↳ mikroC PRO for FT90x General
- ↳ mikroC PRO for FT90x Beta Testing
- ↳ mikroC PRO for FT90x Wish List
- ↳ mikroBasic PRO compiler for FT90x
- ↳ mikroBasic PRO for FT90x General
- ↳ mikroBasic PRO for FT90x Beta Testing
- ↳ mikroBasic PRO for FT90x Wish List
- ↳ mikroPascal PRO for FT90x
- ↳ mikroPascal PRO for FT90x General
- ↳ mikroPascal PRO for FT90x Beta Testing
- ↳ mikroPascal PRO for FT90x Wish List
- ↳ 8051 PRO Compilers
- ↳ 8051 Compilers General
- ↳ mikroC PRO for 8051
- ↳ mikroC PRO for 8051 General
- ↳ mikroC PRO for 8051 Beta Testing
- ↳ mikroC PRO for 8051 Wish List
- ↳ mikroBasic PRO compiler for 8051
- ↳ mikroBasic PRO for 8051 General
- ↳ mikroBasic PRO for 8051 Beta Testing
- ↳ mikroBasic PRO for 8051 Wish List
- ↳ mikroPascal PRO for 8051
- ↳ mikroPascal PRO for 8051 General
- ↳ mikroPascal PRO for 8051 Beta Testing
- ↳ mikroPascal PRO for 8051 Wish List
- ↳ ARM PRO Compilers
- ↳ ARM Compilers General
- ↳ mikroC PRO for ARM
- ↳ mikroC PRO for ARM General
- ↳ mikroC PRO for ARM Beta Testing
- ↳ mikroC PRO for ARM Wish List
- ↳ mikroBasic PRO for ARM
- ↳ mikroBasic PRO for ARM General
- ↳ mikroBasic PRO for ARM Beta Testing
- ↳ mikroBasic PRO for ARM Wish List
- ↳ mikroPascal PRO for ARM
- ↳ mikroPascal PRO for ARM General
- ↳ mikroPascal PRO for ARM Beta Testing
- ↳ mikroPascal PRO for ARM Wish List
- ↳ Older versions of Compilers
- ↳ Older versions of mikroC Compilers
- ↳ mikroC for PIC
- ↳ mikroC General
- ↳ mikroC Beta Testing
- ↳ mikroC Wish List
- ↳ mikroC for dsPIC30/33 and PIC24
- ↳ mikroC for dsPIC30/33 and PIC24 General
- ↳ mikroC for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroC for dsPIC30/33 and PIC24 Wish List
- ↳ RSC-4x mikroC
- ↳ RSC-4x mikroC General
- ↳ RSC-4x mikroC Wish List
- ↳ mikroC Beta testing
- ↳ Older versions of mikroBasic Compilers
- ↳ mikroBasic compiler for PIC
- ↳ mikroBasic General
- ↳ mikroBasic Beta Testing
- ↳ mikroBasic Wish List
- ↳ mikroBasic compiler for dsPIC30/33 and PIC24
- ↳ mikroBasic for dsPIC30/33 and PIC24 General
- ↳ mikroBasic for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroBasic for dsPIC30/33 and PIC24 Wish List
- ↳ mikroBasic for dsPIC30/33 and PIC24 Bug List
- ↳ Obsolete Project: mikroBasic compiler for AVR
- ↳ mikroBasic for AVR General
- ↳ mikroBasic for AVR Wish List
- ↳ mikroBasic Beta testing
- ↳ Older versions of mikroPascal Compilers
- ↳ mikroPascal compiler for PIC
- ↳ mikroPascal FAQ
- ↳ mikroPascal General
- ↳ mikroPascal Beta Testing
- ↳ mikroPascal Wish List
- ↳ mikroPascal Bug List
- ↳ mikroPascal compiler for dsPIC30/33 and PIC24
- ↳ mikroPascal for dsPIC30/33 and PIC24 General
- ↳ mikroPascal for dsPIC30/33 and PIC24 Beta Testing
- ↳ mikroPascal for dsPIC30/33 and PIC24 Wish List
- ↳ mikroPascal for dsPIC30/33 and PIC24 Bug List
- ↳ Obsolete Project: mikroPascal compiler for AVR
- ↳ mikroPascal for AVR General
- ↳ mikroPascal for AVR Wish List
- ↳ mikroPascal Beta testing
- ↳ Library Development Discussion
- ↳ Code Requests
- Additional Software
- ↳ Visual TFT Software
- ↳ Visual TFT General
- ↳ Visual TFT Beta Testing
- ↳ Visual TFT Wish List
- ↳ Visual GLCD Software
- ↳ Visual GLCD General
- ↳ Visual GLCD Beta Testing
- ↳ Visual GLCD Wish List
- ↳ Package Manager Software
- ↳ Package Manager General
- ↳ Package Manager Beta Testing
- ↳ Package Manager Wishlist
- ↳ GLCD Font Creator Software
- ↳ SpeakUp Software
- ↳ Timer Calculator
- ↳ CAN Calculator
- ↳ mikroBootloader
- Hardware
- ↳ Development Boards
- ↳ CODEGRIP programmer and debugger
- ↳ Mikromedia
- ↳ mikroProg™ programmer and debugger
- ↳ Development Boards Wishlist
- ↳ Review
- ↳ Click Boards release
- ↳ Hexiwear
- Website & Forums
- ↳ Libstock Discussion
- ↳ Product Announcements
- ↳ Website & Forums General Discussion
- ↳ Website & Forums Wishlist
- ↳ User Projects