Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <p18f4321.h>
- #include <stdio.h>
- #include <math.h>
- #include <usart.h>
- #pragma config OSC = INTIO2
- #pragma config WDT=OFF
- #pragma config LVP=OFF
- #pragma config BOR =OFF
- #define SEC_LED PORTEbits.RE0 //sets red LED to RE0
- #define NS_RED PORTAbits.RA4 //sets NS RED LED to RA4
- #define NS_GREEN PORTAbits.RA5 //sets NS GREEN LED to RA5
- #define NS_LT_RED PORTCbits.RC4 //sets NS LT RED LED to RC4
- #define NS_LT_GREEN PORTCbits.RC5 //sets NS LT GREEN LED to RC5
- #define EW_RED PORTAbits.RA0 //sets EW RED LED to RA0
- #define EW_GREEN PORTAbits.RA1 //sets EW GREEN LED to RA1
- #define EW_LT_RED PORTAbits.RA2 //sets EW LT RED LED to RA2
- #define EW_LT_GREEN PORTAbits.RA3 //sets EW LT GREEN LED to RA3
- char sevenseg[10] ={0x40, 0x79, 0x24, 0x30, 0x19, 0x12, 0x02, 0x78, 0x00, 0x18}; //seven segment A-G code
- void init_UART()
- {
- OpenUSART (USART_TX_INT_OFF & USART_RX_INT_OFF &
- USART_ASYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX &
- USART_BRGH_HIGH, 25);
- OSCCON = 0x60;
- }
- void putch(char c) //makes it so the tera tree functions
- {
- while(!TRMT);
- TXREG = c;}
- void DO_INIT() //step one
- {
- //ADCON0=0x11; // change to AN4
- ADCON1=0x07;//0x19; // select pins AN0 through AN5 as analog signal, VDD-VSS as
- //ADCON2=0xA9; // right justify the result. Set the bit conversion time (TAD) and
- TRISA = 0xff; //outputs
- TRISB = 0x00; //inputs and outputs CHECK!!!!
- TRISC = 0x00; //outputs
- TRISD = 0x00; //outputs
- TRISE = 0x00; //outputs
- }
- void Wait_Half_Second()
- {
- int I; //define integer i
- for(I=0; I<32700; I++); //create delay loop for .5 seconds
- }
- void Wait_One_Second()
- {
- Wait_Half_Second(); //delay 1/2 a second
- SEC_LED = 0; //led off
- Wait_Half_Second(); //delay 1/2 a second
- SEC_LED = 1; //led on
- }
- void SET_NS(int color)
- {int R, G; //integers R and G represent the defined leds
- if(color=1){ // case: red= 01
- R=1;
- G=0;
- }
- else if(color=2){ // case: yellow= 11
- R=1;
- G=1;
- }
- else if(color=3){ // case: green= 10
- R=0;
- G=1;}
- else{ // case: off= 00
- R=0;
- G=0;
- }
- NS_RED =R; //set R=RED LED
- NS_GREEN =G; //set G=GLED
- }
- void SET_NS_LT(int color)
- {int R, G;
- if(color=1){
- R=1;
- G=0;
- }
- else if(color=2){
- R=1;
- G=1;
- }
- else if(color=3){
- R=0;
- G=1;}
- else{
- R=0;
- G=0;
- }
- NS_LT_RED =R;
- NS_LT_GREEN =G;
- }
- void SET_EW(int color)
- {int R, G;
- if(color=1){
- R=1;
- G=0;
- }
- else if(color=2){
- R=1;
- G=1;
- }
- else if(color=3){
- R=0;
- G=1;}
- else{
- R=0;
- G=0;
- }
- EW_RED =R;
- EW_GREEN =G;
- }
- void SET_EW_LT(int color)
- {int R, G;
- if(color=1){
- R=1;
- G=0;
- }
- else if(color=2){
- R=1;
- G=1;
- }
- else if(color=3){
- R=0;
- G=1;}
- else{
- R=0;
- G=0;
- }
- EW_LT_RED =R;
- EW_LT_GREEN =G;
- }
- void Do_Display(void){
- int Rint, H, L, abc, R; //define terms for seven segment
- if(R<10.0){ //case R is less than 10
- H= (int)R; // A point
- L= (int)((R-H)*10); // 0."A" point
- abc=0;} //DP is off
- else{ //R is greater than 9.9999
- abc=1; //DP is off
- Rint= (int)R; // set A as int
- H=Rint/10; // high is Ab
- L=Rint%10; //low is aB
- }
- PORTD = sevenseg[L]; //set portd to l
- int I = sevenseg[H]; //insert interger i
- PORTC= I&0x0F;
- PORTB= ((I&0x70)>>4);
- }
- void main()
- {
- int i;
- DO_INIT();
- init_UART();
- while(1)
- {
- for (i=0; i<4;i++)
- {
- SET_NS(i);
- SET_NS_LT(i);
- SET_EW(i);
- SET_EW_LT(i);
- Wait_One_Second();
- }
- //Do_Display();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement