Skip to content

PIC12F683 using Digital I/O

One of the simplest usages for any MCU is controlling its digital I/O (Input/Output) ports.

In one of my recent projects, I was required to use the PIC12F683 from Microchip. an 8 Pin MCU with many peripheral features like Analog Comparator, A/D Converter, Timers and PWM.

The development tools were MPLAB 8.40 from Microchip and HI-TECH C Complier for PIC10/12/16. Creating the project and adding the main c file was pretty straight forward. The tricky part was initializing the MCU ports for digital I/O. I used the GP0, GP1, GP2, GP4 and GP5, as you can see in the datasheet, every port has at least 4 different configurations. After briefly reading the datasheet and googled, I finally found the “magic” code.

 

Microchip PIC12F683 datasheet:

http://ww1.microchip.com/downloads/en/DeviceDoc/41211D_.pdf

Download the latest MPLAB:

http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en019469&part=SW007002

Download HI-TECH C Compiler:

http://www.htsoft.com/products/compilers/PICClite.php

 

Here’s an example of simple square wave generator:

 

#include <htc.h>

#include <stdlib.h>

 

__CONFIG(UNPROTECT & BOREN & MCLRDIS & PWRTEN & WDTDIS & INTIO);

 

#define _XTAL_FREQ 4000000

 

void main(void)

{

unsigned char delayCount;

 

GPIO = 0; clear all GPIO pins

ANSEL = 0; // disable analog inputs

TRISIO = 0; // set all GPIO pins to output

OPTION = 0b11010000;

CMCON0 = 0; // disable comparator 0

CMCON1 = 0; // disable comparator 1

 

While(1)

{

GPIO = 0×7;

for (delayCount = 0 ; delayCount < 10 ; delayCount++)

__delay_ms(100);

 

GPIO = 0;

for (delayCount = 0 ; delayCount < 10 ; delayCount++)

__delay_ms(100);

}

}

 

GPIO – General Purpose I/O

ANSEL – Analog Select Register

TRISIO – Input or Output GPIO selection

OPTION – Option Register

CMCON0 – Comparator 0 Configuration Register

CMCON1 – Comparator 1 Configuration Register

Managing users in ASP.NET MVC

User management in websites mostly required for E-Commerce, posting comments, Emails and more…

ASP.NET framework has built-it API for handling Membership, Roles and profiles.

 

Membership (System.Web.Security.MembershipProvider) – User accounts access and registration.

Roles (System.Web.Security.RoleProvider) – Organizing users into groups (for example: Admin, regular user, banned).

Profiles (System.Web.Profile.ProfileProvider) – Storing extra data per-user.

  

If you have a small size website, you can use the built-in SQL provider (SqlMembershipProvider) with SQL Server Express.

For medium/large corporate website, with regular user administration requirements, use the Active Directory Membership Provider.

If the built-in providers don’t suite you well, create a custom one of your own, by inherit the classes and override the methods with your own code.

 Regarding the UI (now we’re getting to MVC), ASP.NET provides WebForms and membership controls for login/logout but you can’t use them in ASP.NET MVC.

You need to create your own MVC views for login/logout.

So what should you choose, the built-in providers or create your own providers? … Good question.

It depends on how much time you got, experience with data storage (in DB or maybe in XML files), security level and scalability of your website.

If you plan to improve and expand your website in the future, I advise you to consider building your own providers.

You will be able to fully control over security, adding extra data to users, manage large scale websites and much more!

 

A few related links:
Creating the Membership schema in SQL Server: http://www.asp.net/learn/security/tutorial-04-cs.aspx

Creating and managing Roles: http://www.asp.net/learn/security/tutorial-09-cs.aspx

 

MembershipProvider class: http://msdn.microsoft.com/en-us/library/system.web.security.membershipprovider.aspx

RoleProvider class: http://msdn.microsoft.com/en-us/library/system.web.security.roleprovider.aspx

ProfilesProvider class: http://msdn.microsoft.com/en-us/library/system.web.profile.profileprovider.aspx

 ASP.NET MVC Membership Starter Kit: http://www.codeplex.com/MvcMembership

DPAPI Decrypt Request Failed exception

For the last couple of days, I’ve been dealing with a web hosting service “mistake”. they decided to limit the usage of trust level attribute, at the web.config file.

so suddenly, the code couldn’ t decrypt the connection string and a nice exception flashed into my eyes:

“System.Security.SecurityException : Request Failed”

at the web.config i used <trust level=”Full” originUrl=”/”> to grant full access to the code, and for opening the configuration:

Configuration cfg = WebConfigurationManager.OpenWebConfiguration(“/”);

ConnectionStringsSectionsection = cfg.ConnectionStrings;

 

the Exception popped from the first line. so how you get your configuration from a lower trust level ?!

instead using OpenWebConfiguration and getting the ConnectionStrings property, you can write the following line:

 

 ConnectionStringsSection section = (ConnectionStringsSection)WebConfigurationManager.GetSection(“connectionStrings”); 

finally, i works great under Medium trust level!!

Isaac.

First Post

Welcome, i’m Isaac :)

for the next and many posts to come, i will help and guide you on many subjects related to software and hardware issues.

of course, if you have any specific questions , feel free to write back or post a comment!

 :)

Isaac.