i need help to program the pic16f877a....

Discussion in 'Embedded Systems and Microcontrollers' started by hosalya, Oct 26, 2010.

  1. hosalya

    Thread Starter New Member

    Oct 26, 2010
    7
    0
    im doing my project using pic16f877a mobile library robot which need to scan and take the book from the book shelf...Im already programmed the line track...but nw the problem is i need to program the arm for the robot....
    plz any one who can help me to do this program...bcz im tried my level best to do the program for arm bt its nt working....

    the things tat need to be consider is the pic should on the web cam to start the book rack after scanning the book rack then the robot will process the image whther the book code insert by the user was been place in that particular book shelf or not.If yes the webcam send a signal to pic to turn the side of the book rack and the pic will send a signal to webcam to start its scanning process from the beginning of the rack till the end of the rack(in each level of the book shelf).If the book is detected the webcam will send a signal to the pic to start its work to give instruction to the arm of the robot the take out the particular book from the book shelf.After that the robot will back to the starting place.



    im using line track for the navigation of the robot using 4- infrared sensor (left move, right move,forward and backward).

    for the arm part im using power window motor to lift the arm of the robot up and down (according to the book shelf level =5) .for this up and down mechanism im required to use proximate sensor to detect whether the arm is in which level.the proximate sensor is placed in body of the robot and the level of the book shelf.If the proximate sensor placed in body of the robot equal to the level of the book shelf the arm will stopped from moved . if the book nt placed in that level the arm will move up/down.


    after detecting the book where its placed in the book shelf the hook type arm which attached with the switch type sensor will move towards the book to pick up the book from the book shelf. After that the robot return to the starting place.



    this is the program that need to create....bt im facing alot of problem to do it...plz help me .....i need it very urgent...because need to submit the coding report by this 3 nov 2010....plz help me i dnt have any other choice except asking for help....
     
  2. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    Post your schematics and code you already have. A photo of the robot might be helpful.

    PIC and webcam. How did you connect them?
     
    hosalya likes this.
  3. retched

    AAC Fanatic!

    Dec 5, 2009
    5,201
    312
    You will need reference points for the arm-cam to recognize when the bottom and top and leftmost rightmost ends of the shelf.

    If you have a row of same colored encyclopedias, hoy is the bot to distinguish each book from the next?

    A hook to grab the top of the book to tilt it out would help give the "pinchers" something to grab. You WILL also need a place holder to keep other books from falling into the space that the picked book was taking up. Else you will have a problem "returning" the book.


    I understand your urge to use a PIC, but a $47(at quantity) credit-card-sized computer would make this a ell-of-a lot easier if space is an issue. Wi-fi ready to talk to the wireless network installed at the library. Great for realtime locating and other on-the-fly updates.

    You can use linux or windows and harddrives to store the voluminous amount of info like images of the book spines for recognition and other complexities

    http://gizmodo.com/184234/credit-card+sized-pc
     
  4. bertus

    Administrator

    Apr 5, 2008
    15,645
    2,344
  5. hosalya

    Thread Starter New Member

    Oct 26, 2010
    7
    0
    the pic function when the webcam send signal to him....


    this the coding for line track tat i ve created
    but i dnt know how to do programming for the arm part
    somemore i dnt f any circuit diagram for this project bcz i dnt know the arm part
    if line track i gt using 4 IR sensor n encoder...n using dc motor...
    somemore i dnt know whether tis coding can work or nt..try in proteus can bt in reality i dnt know
    plz help me the coding part for line track combine the arm part for the robot..
    plz im really need it..thanks anyway for the guide...

    Code ( (Unknown Language)):
    1.  
    2. #include <pic.h>
    3. __CONFIG ( 0x3F32 );
    4. #define MHZ *1000L
    5. #define KHZ *1
    6. #define DelayUs(x)
    7.  
    8. //int x;
    9. //unsigned char _dcnt;
    10. //__dcnt = (((x)*(20MHZ))/ (24MHZ)) |1;
    11. //while(--__dcnt != 0)
    12. //continue
    13. //__dcnt = (((x)* (20MHZ))
    14. //while(--__dcnt != 0)
    15. //continue
    16.  
    17. #define arm RC3
    18. #define IR_1 RD0
    19. #define IR_2 RD2
    20. #define IR_3 RD3
    21. #define IR_4 RD1
    22. #define DC_nleft RB0
    23. #define DC_pleft RB1
    24. #define Speed_l CCPR1L
    25. #define DC_nright RB5
    26. #define DC_pright RB4
    27. #define Speed_r CCPR2L
    28. int b=0;
    29. unsigned int cnt=0;
    30. void initialize(void);
    31. void forward(void);
    32. void stop(void);
    33. void left(void);
    34. void right(void);
    35. void reverse(void);
    36. void line_follow(void);
    37. void DelayMs(unsigned char y);
    38. void delay(unsigned long data);
    39. void loading(void);
    40. void unloading(void);
    41. void turun (void);
    42. void interrupt isr(void)
    43. {
    44. if(TMR0IF==1)
    45. {
    46. TMR0IE=0;
    47. TMR0=61;
    48. int j;
    49. for(j=1; j<=5 ;j++);
    50. cnt=j;
    51. if(cnt==1)
    52. {
    53. arm=1;
    54. DelayUs(250);
    55. DelayUs(250);
    56. DelayUs(250);
    57. DelayUs(250);
    58. DelayUs(250);
    59. DelayUs(250);
    60. arm=0;
    61. DelayMs(18);
    62. DelayUs(250);
    63. DelayUs(250);
    64. }
    65. if(cnt==2)
    66. {
    67. arm=1;
    68. DelayMs(250);
    69. DelayMs(250);
    70. DelayMs(250);
    71. arm=0;
    72. DelayMs(19);
    73. DelayUs(250);
    74. }
    75. if(cnt==3)
    76. {
    77. arm=1;
    78. DelayMs(250);
    79. DelayMs(250);
    80. DelayMs(250);
    81. arm=0;
    82. DelayMs(20);
    83. DelayUs(250);
    84. }
    85. if(cnt==4)
    86. {
    87. arm=1;
    88. DelayMs(250);
    89. DelayMs(250);
    90. DelayMs(250);
    91. arm=0;
    92. DelayMs(21);
    93. DelayUs(250);
    94. }
    95. if(cnt==5)
    96. {
    97. arm=1;
    98. DelayMs(250);
    99. DelayMs(250);
    100. DelayMs(250);
    101. arm=0;
    102. DelayMs(22);
    103. DelayUs(250);
    104. }
    105. TMR0IE=1;
    106. TMR0IF=0;
    107. }
    108. }
    109. void main(void)
    110. {
    111. initialize();
    112. line_follow();
    113. }
    114. void initialize()
    115. {
    116. TRISB=0b00000000;
    117. TRISC=0b11000000;
    118. TRISD=0b00001111;
    119. TRISE=0b00000111;
    120. PORTA=0; PORTB=0; PORTC=0; PORTD=0; PORTE=0;
    121. PR2=255;
    122. T2CON=0b00000100;
    123. CCP1CON=0b00001100;
    124. CCP2CON=0b00001100;
    125. TMR0 = 61;
    126. OPTION = 0b10000111;
    127. INTCON = 0b11000000;
    128. }
    129. void line_follow()
    130. {
    131. int b=0;
    132. while(1)
    133. {
    134. if((IR_1==0)&&(IR_2==0)&&(IR_3==0)&&(IR_4==0))
    135. {
    136. if(b==1)
    137. {
    138. turun();
    139. }
    140. else
    141. {
    142. forward();
    143. }
    144. }
    145. if((IR_1==0)&&(IR_2==0)&&(IR_3==0)&&(IR_4==1))
    146. {
    147. reverse();
    148. }
    149. if((IR_1==0)&&(IR_2==1)&&(IR_3==0)&&(IR_4==0))
    150. {
    151. forward();
    152. }
    153. if((IR_1==0)&&(IR_2==1)&&(IR_3==0)&&(IR_4==1))
    154. {
    155. forward();
    156. }
    157. if((IR_1==1)&&(IR_2==0)&&(IR_3==0)&&(IR_4==0))
    158. {
    159. left();
    160. }
    161. if((IR_1==0)&&(IR_2==0)&&(IR_3==1)&&(IR_4==0))
    162. {
    163. right();
    164. }
    165. if((IR_1==0)&&(IR_2==1)&&(IR_3==1)&&(IR_4==0))
    166. {
    167. stop();
    168. }
    169. if((IR_1==0)&&(IR_2==1)&&(IR_3==1)&&(IR_4==1))
    170. {
    171. stop();
    172. }
    173. if((IR_1==1)&&(IR_2==1)&&(IR_3==0)&&(IR_4==0))
    174. {
    175. forward();
    176. while(IR_3!=1)
    177. {
    178. left();
    179. }
    180. forward();
    181. }
    182. if((IR_1==0)&&(IR_2==1)&&(IR_3==1)&&(IR_4==0))
    183. {
    184. forward();
    185. while(IR_1!=1)
    186. {
    187. right();
    188. }
    189. forward();
    190. }
    191. if((IR_1==1)&&(IR_2==1)&&(IR_3==1)&&(IR_4==1))
    192. //object detection
    193. {
    194. if(b==0)
    195. {
    196. forward();
    197. delay(100000);
    198. stop();
    199. loading();
    200. forward();
    201. b++;
    202. }
    203. else
    204. {
    205. stop();
    206. }
    207. }
    208. }
    209. }
    210. void forward()
    211. {
    212. DC_pright=1;
    213. DC_nright=0;
    214. DC_pleft=0;
    215. DC_nleft=1;
    216. Speed_l=255;
    217. Speed_r=255;
    218. }
    219. void right()
    220. {
    221. DC_pright=1;
    222. DC_nright=0;
    223. DC_pleft=0;
    224. DC_nleft=1;
    225. Speed_l=255;
    226. Speed_r=200;
    227. }
    228. void left()
    229. {
    230. DC_pright=1;
    231. DC_nright=0;
    232. DC_pleft=0;
    233. DC_nleft=1;
    234. Speed_l=200;
    235. Speed_r=255;
    236. }
    237. void stop()
    238. {
    239. DC_pright=1;
    240. DC_nright=0;
    241. DC_pleft=0;
    242. DC_nleft=1;
    243. Speed_l=0;
    244. Speed_r=0;
    245. }
    246. void reverse()
    247. {
    248. DC_pright=0;
    249. DC_nright=1;
    250. DC_pleft=1;
    251. DC_nleft=0;
    252. Speed_l=255;
    253. Speed_r=255;
    254. }
    255. void DelayMs(unsigned char y)
    256. {
    257. unsigned char i;
    258. do {
    259. i = 4;
    260. do {
    261. DelayUs(250);
    262. } while(--i);
    263. } while(--y);
    264. }
    265. void delay(unsigned long data)
    266. {
    267. for( ;data>0;data-=1);
    268. }
    269. void loading()
    270. {
    271. cnt=1;
    272. TMR0IE=1;
    273. }
    274. void unloading()
    275. {
    276. cnt=2;
    277. TMR0IE=1;
    278. }
    279. void turun()
    280. {
    281. {
    282. stop();
    283. unloading();
    284. reverse();
    285. delay(300000);
    286. right();
    287. delay(300000);
    288. stop();
    289. }
    290. }
    291.  
    292.  
     
    Last edited by a moderator: Oct 29, 2010
  6. bertus

    Administrator

    Apr 5, 2008
    15,645
    2,344
  7. hosalya

    Thread Starter New Member

    Oct 26, 2010
    7
    0
    hi can help me to program pic16f877a for movements of motor power window up and down from level 1 until level 4 using proximity sensor as input to make sure the motor stop at each level like elavator function
     
  8. hosalya

    Thread Starter New Member

    Oct 26, 2010
    7
    0
    hi me hosalya
    can i ask u for help?
    u have yahoo email...
    can u add me there u make easy contact u
     
    Last edited: Nov 19, 2010
Loading...