473,320 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

I have problem in embedded c coding for digital password lock it gives the message "p

Expand|Select|Wrap|Line Numbers
  1. #include <AT89X51.H> 
  2. #define EE_SCL P1_0 
  3. #define EE_SDA P1_1 
  4. #define LCD_E P1_7 
  5. #define LCD_RW P1_6 
  6. #define LCD_RS P1_5 
  7. #define LCD_DATA P3 
  8. #define buzz P0_3 
  9. #define led P1_2 
  10. void cmnwrt(int); 
  11. void datawrt(char); 
  12. char keypad_refresh(); 
  13. void init(); 
  14. void delay(unsigned i); 
  15. void get_sntnc(char *); 
  16. void print_msg(char*,char); 
  17. void EE_write(unsigned int, char); 
  18. char EE_read(unsigned int); 
  19. void EE_strt(); 
  20. void EE_stop(); 
  21. char EE_shin(); 
  22. void EE_shout(char); 
  23. //---------------------------------------- 
  24. //---------------------------------------- 
  25. int main(){ 
  26. char tmp[17],i,j; 
  27. init(); 
  28. cmnwrt(0x80); 
  29. led=1; 
  30. while(1){ 
  31. if(EE_read(0)!='p'||EE_read(1)!='='){ 
  32. np: 
  33. cmnwrt(1); 
  34. print_msg("Enter new pass:\0",0x80); 
  35. get_sntnc(tmp); 
  36. EE_write(0,'p'); 
  37. EE_write(1,'='); 
  38. for(i=0;tmp[i];i++) 
  39. EE_write(i+2,tmp[i]); 
  40. EE_write(i+2,0); 
  41. rpa: 
  42. cmnwrt(1); 
  43. print_msg("Enter the pass:\0",0x80); 
  44. get_sntnc(tmp); 
  45. for(i=0,j=0;;i++){ 
  46. if(tmp[i]!=EE_read(i+2)){ 
  47. j=-1; 
  48. break; 
  49. if(!tmp[i]) 
  50. break; 
  51. cmnwrt(1); 
  52. if(j==-1) 
  53. print_msg("Pass is wrong!\0",0x80); 
  54. led=1; 
  55. buzz=1; 
  56. delay(5000); 
  57. buzz=0; 
  58. goto rpa; 
  59. else 
  60. print_msg("Pass is right!\0",0x80); 
  61. led=0; 
  62. buzz=0; 
  63. delay(5000); 
  64. led=1; 
  65. cmnwrt(1); 
  66. print_msg("*=change pass\0",0x80); 
  67. print_msg("#=back\0",0xc0); 
  68. ka: 
  69. do 
  70. i=keypad_refresh(); 
  71. while(i==-1); 
  72. if(i==0x3a) 
  73. goto np; 
  74. else if(i==0x3c) 
  75. goto rpa; 
  76. else 
  77. goto ka; 
  78. //------------------------------------ 
  79. //------------------------------------ 
  80. void print_msg(char *msg, char line){ 
  81. char i; 
  82. cmnwrt(line); 
  83. for(i=0;*(msg+i);i++) 
  84. datawrt(*(msg+i)); 
  85. //------------------------------------ 
  86. //------------------------------------ 
  87. char keypad_refresh(){ 
  88. char tmp,row,cl; 
  89. P2 = 0xf0; 
  90. if(!P2_4) 
  91. row = 0; 
  92. else if(!P2_5) 
  93. row = 1; 
  94. else if(!P2_6) 
  95. row = 2; 
  96. else if(!P2_7) 
  97. row = 3; 
  98. else 
  99. return -1; 
  100. P2 = 0xff; 
  101. P2 = 0x0f; 
  102. if(!P2_2) 
  103. cl = 0; 
  104. else if(!P2_1) 
  105. cl = 1; 
  106. else if(!P2_0) 
  107. cl = 2; 
  108. else 
  109. return -1; 
  110. tmp = row*3+cl+1; 
  111. if(tmp == 11) 
  112. tmp = 0; 
  113. return tmp|0x30; 
  114. //-------------------------------------------------- 
  115. //-------------------------------------------------- 
  116. void get_sntnc(char *str) { 
  117. char i,j,z; 
  118. for(i=0;i<17;i++) 
  119. *(str+i)=0; 
  120. i=0; 
  121. while(1){ 
  122. cmnwrt(0xc0); 
  123. for(z=0;z<16;z++) 
  124. if(*(str+z)) 
  125. datawrt(*(str+z)); 
  126. else 
  127. datawrt(' '); 
  128. delay(70); 
  129. do 
  130. j = keypad_refresh(); 
  131. while(j==-1); 
  132. if(j==0x3c){ 
  133. *(str+i)=0; 
  134. break; 
  135. }
  136. else if(j==0x3a){ 
  137. if(i>0){ 
  138. i--; 
  139. *(str+i)=0; 
  140. }
  141. else{ 
  142. if(i<=15){ 
  143. *(str+i)=j; 
  144. i++; 
  145. //-------------------------------------------------- 
  146. //-------------------------------------------------- 
  147. void init() { 
  148. int i; 
  149. P0=P1=P2=P3=0; 
  150. //initialize LCD 
  151. LCD_RS = 0; 
  152. LCD_RW = 0; 
  153. delay(30); 
  154. cmnwrt(0x3f); 
  155. delay(20); 
  156. cmnwrt(0x3f); 
  157. delay(10); 
  158. cmnwrt(0x3f); 
  159. delay(5); 
  160. cmnwrt(0x38); 
  161. cmnwrt(0x01); 
  162. cmnwrt(0x0c); 
  163. //initialize EEPROM 
  164. EE_SDA = 1; 
  165. for(i=0;i<10;i++) { 
  166. EE_SCL = 1; 
  167. i=i; //delay 
  168. EE_SCL = 0; 
  169. //-------------------------------------------------- 
  170. //-------------------------------------------------- 
  171. void delay(unsigned i) { 
  172. TMOD = 1; 
  173. for (;i>0;i--) { 
  174. TH0 = 0xFc; //0xFFFF - 0xFc17 = 1000 (decimal) -> 1ms for 12MH crystal 
  175. TL0 = 0x17; 
  176. TR0 = 1; 
  177. while(!TF0); 
  178. TR0 = 0; 
  179. TF0 = 0; 
  180. //-------------------------------------------------- 
  181. //-------------------------------------------------- 
  182. void cmnwrt(int cmn) { 
  183. LCD_DATA = cmn; 
  184. LCD_RS = 0; 
  185. LCD_RW = 0;
  186. LCD_E = 1; 
  187. LCD_E = 0; 
  188. delay(2); 
  189. void datawrt(char ch) { 
  190. LCD_DATA = ch; 
  191. LCD_RS = 1; 
  192. LCD_RW = 0; 
  193. LCD_E = 1; 
  194. LCD_E = 0; 
  195. delay(2); 
  196. //--------------------------------------------------- 
  197. //--------------------------------------------------- 
  198. //Write into EEPROM 
  199. void EE_write(unsigned int addr, char dta){ 
  200. char chtmp; 
  201. CY = 0; 
  202. EE_strt(); 
  203. EE_shout(0xA0); 
  204. chtmp=addr>>8; 
  205. EE_shout(chtmp); 
  206. chtmp=addr; 
  207. EE_shout(chtmp); 
  208. EE_shout(dta); 
  209. EE_stop(); 
  210. delay(13); 
  211. //Reading from EEPROM 
  212. char EE_read (unsigned int addr) { 
  213. char chtmp; 
  214. CY=0; 
  215. EE_strt(); 
  216. EE_shout(0xA0); 
  217. chtmp=addr>>8; 
  218. EE_shout(chtmp); 
  219. chtmp=addr; 
  220. EE_shout(chtmp); 
  221. EE_strt(); 
  222. EE_shout(0xA1); 
  223. chtmp=EE_shin(); 
  224. EE_stop(); 
  225. return chtmp; 
  226. //Start 
  227. void EE_strt() { 
  228. EE_SDA=1; 
  229. EE_SCL=1; 
  230. EE_SDA=0; 
  231. EE_SCL=0; 
  232. //Stop 
  233. void EE_stop() { 
  234. EE_SCL=0; 
  235. EE_SDA=0; 
  236. EE_SCL=1; 
  237. EE_SDA=1; 
  238. //Shift out 
  239. void EE_shout(char sho) { 
  240. unsigned char i,j; 
  241. for(j=0,i=0;i<8;i++) { 
  242. j/=2; 
  243. if(!j) 
  244. j=128; 
  245. if(sho&j) 
  246. CY=1; 
  247. else
  248. CY=0; 
  249. EE_SDA=CY; 
  250. EE_SCL=1; 
  251. j=j; //delay 
  252. EE_SCL=0; 
  253. EE_SDA=1; 
  254. EE_SCL=1; 
  255. j=j; //delay 
  256. CY=EE_SDA; 
  257. EE_SCL=0; 
  258. //Shift in 
  259. char EE_shin() { 
  260. char i,shi = 0; 
  261. EE_SDA = 1; 
  262. for(i=0;i<8;i++) { 
  263. CY=0; 
  264. shi<<=1; 
  265. EE_SCL=1; 
  266. i=i; 
  267. CY=EE_SDA; 
  268. EE_SCL=0; 
  269. if(CY) 
  270. shi++; 
  271. EE_SDA=1; 
  272. EE_SCL=1; 
  273. i=i; //delay 
  274. EE_SCL=0; 
  275. return shi; 
  276. }
Apr 7 '14 #1
5 1309
weaknessforcats
9,208 Expert Mod 8TB
May be you could explain a little further. The error occurs when the code runs, when it links, or when it compiles?

What is the code supposed to do? There are no comments whatever.

I suggest that you step through this code using your debugger. Since you know what you are looking for, and I don't, you doing the debugging will get results instead of me.
Apr 7 '14 #2
donbock
2,426 Expert 2GB
Also, what is the error message?
(Only the first letter appears in the title of your post.)
Apr 8 '14 #3
there are no syntax errors.
The program stores the newly entered password and must display the message" pass is right" when the password again entered is correct but the program always displays "pass is worng" message only.
Apr 9 '14 #4
After much debugging only i have posted here.
code must check for the password with the previously entered But the code only displays "pass is wrong" for every correct password also.
Apr 9 '14 #5
weaknessforcats
9,208 Expert Mod 8TB
Your code to make the decision if the password is right or wrong is:

Expand|Select|Wrap|Line Numbers
  1. if (j == -1)...
-1 is an int an j is a char.

Start by making j an int.
Apr 9 '14 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: PiEmme | last post by:
On a Linux server a MySql db is installed. I was able to run mysql and mysqladmin without entering user and password, at first. Later both user and password have become required. Probably after...
4
by: splicemix | last post by:
Hi all, I have recently set up a Drupal website. I am a beginner. My shared host server does not allow nobody@localhost to send emails, and prevents access to php.ini, so I spent some time...
0
by: tsalikivenu | last post by:
Hi i have problem with loading digital certificates.i am currently using asp.net 2003.i have installed wse2.0 here is my code..i want it to load digital certficates to list box..it is...
0
by: icy111 | last post by:
Hi All, I need to generate excel files with password protected in ASP? Kindly help. Thanks in Advance. Regards icy111
12
by: abetown3 | last post by:
Hello. I'm having data entry problems with a database I've created. I'm working in Access 2003 although the db was created in 2000 format. When data entry first began the db allowed for multiple...
1
by: Claudia Fong | last post by:
In my windows form I have a comboBox and a textBox. When I try to write something in the textBox it shows me the error message below: Attempting managed execution inside OS Loader lock. Do not...
9
by: Porkie999 | last post by:
hi i have used this code in my website but have a problem with the header parts where is the problem the error is <?php $myusername = "myusername"; $mypassword = "mypassword"; $areaname...
1
by: rando1000 | last post by:
I have an automated e-mail process that recently broke due to some security we implemented that requires a password for sendmail. Here's my code: Set iMsg = CreateObject("CDO.Message") ...
2
by: johnb773 | last post by:
I have a .txt file that has some PHP coding (<?php echo setUrlVariables(); ?>) embedded into it. It worked fine (the variables actually worked) when I had my PHP file 'include("myfile.txt")'...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.